• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Piflik · Dec 30, 2012 at 04:03 PM · collisioncharactercontrollerlocalscale

Prevent character from phasing through barriers when changing its scale

I have a character that can dynamically change its scale (it is a blob of jello that can split and recombine itself and also shoot and collect bubbles to shrink and grow). If the character stand right next to a collider and then grows, he is able to phase through the object.

Additional colliders don't solve the problem, they merely force the player to shrink/grow multiple times before he can glitch through a wall.

My character uses a CharacterController for collision and movement (characterController.Move()). Growing is done via transform.localScale

Is there a reliable way to force the player out of a collider, after changing its scale, or away from it before?

Comment
Add comment · Show 11
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Piflik · Dec 30, 2012 at 04:54 PM 0
Share

I temporarily solved it by declaring walls and doors danger zones, so my blob gets damaged and repulsed when he hits a wall...not a perfect solution, though...if I keep it like this, I will have to make this clear to the player by using spikes or similar stuff...it is possible to continue like this, but I'm still interested if there is a better way to go about this.

avatar image Fattie · Dec 30, 2012 at 05:36 PM 0
Share

are those two nicknames the same for you dude ?

It's a good question and the answer is for better or worse no, there's no way to do it w/ PhysX based on my investigations anyway

(PX has a policy that "if you break it it's broken". if something ridiculous happens - you "just move" an item, or in your case change it's size, or whatever - anything not physical - it DOES NOT, generally speaking, try to solve the situation.) PhysX is quite different from smart-ass soft-body physics packages (which, after all, are designed to solve precisely problems like you describe).

in this particular game -- couldn't you just check before doing the zoom? that could be the way to go.

I always think "what would you literally do in a real game in the real world?"

say in American Football a player could "expand" or something.

then - quite simply - he wouldn't be able to expand if too near a hazard or whatever.


Another solution:

have you considerer this, take (say) four invisible box colliders (or whatever is relevant for your rig) attached to the player/whatever.

As the player/whatever "expands" ... actually cleverly move these "probes" outwards. to roughly match the expanding boundary, probably a bit ahead of it

In fact, that will "push it away" from walls or the like as it gets bigger.

(Of course you still have problems like "it is in a corridor that is too thin" and the like - so, in sense, you do need "rules" as mentioned above - no matter what.)

some thoughts

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Dec 31, 2012 at 05:31 PM

Growing rigidbodies tend to "push away" from surfaces as they grow. I'm not saying switch to one, but, for your blob, you may start thinking an RB would work better than a character controller, anyway, so one more reason to switch.

RB's can still have the "grow into an overlap" problem. But if they grow slowly enough then the physics step will see the small overlap and decide to push them apart. If may not work as well if you are moving quickly and growing. Just in case, I move them "up" the amount they grow, to keep them from growing through the floor.


For the additional wall colliders you tried, could put them hidden just barely inside/behind other colliders, with "push player away" code. The idea is, if the player is touching them, you know it grew through something and you have a problem. Use OnCollisionStay, and a physics-layer mask to only see the player.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Piflik · Dec 31, 2012 at 06:02 PM 0
Share

The first controller I wrote for my blob was physics-based, using a Rigidbody, but I didn't like the behavior at all...I didn't have immediate enough control over the character, it felt really floaty...I am quite happy with CharacterController.$$anonymous$$ove, although I had to implement gravity myself...I don't think I want to go back to using a Rigidbody, since I would have to spend much time on writing a good controller that will probably not ever behave as well as the CharacterController does...

Growing is quite fast...it is either +0.1 when collecting a bubble ($$anonymous$$imum scale is 0.2, maximum 1), or up to +0.5 when recombining (it gos in one frame from 0.5 to 0 when absorbing the clone with both at full health).

Anyways...I don't think I really need walls, and I can live with dangerous doors ^^

avatar image Owen-Reynolds · Jan 01, 2013 at 04:25 PM 0
Share

$$anonymous$$ight look nicer if you grow over time. Even 1/3 second to grow by 0.5 looks like "right away," but without the popping effect.

And, 1/3rd sec is maybe 20 frames, so would be growing by only 0.025 per frame. That slow a rate, even with a charController, might avoid wall pop-through. I think controller.$$anonymous$$ove is what looks around for other colliders and reacts, so might make sure you always call it, even when speed is 0.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics AddForce reduced when 3 objects are colliding 1 Answer

How to trigger different animations depending on where a gameobject collides? 1 Answer

OnCollisionEnter not working with CharacterController 1 Answer

OnCollisionEnter Push Object Problem 0 Answers

Mesh separating from CharacterController 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges