Collider sends objects flying during animation

Hi everyone, could use some help with the following issue.

I have animations that involve the player ducking, then going back to standing again.
When the player is ducking, the collider is smaller so that someone else can jump over the player.
As the animation goes back to standing, the collider increases back to its original size.

The problem is that if someone happens to be directly above the player at this time, he is launched in the air, like this:

So, any suggestions on how to deal with this?
Maybe a way to push any objects/characters that are in the way away, without launching them?
Or maybe I should simply freeze the animation until there is room to stand up?

I could really use some advice on this. Thank you very much for your time! :slight_smile:

Does you character have very little mass? Because I don’t think the player should be flung that high.

Thank you for the suggestion, I’ve increased the mass to 100, but the result was exactly the same… Maybe because both characters have the same mass? Or maybe because when the collider increases in size and pushes away other objects, it directly changes their velocity (regardless of mass)?

I made a simple test scene, trying to replicate your problems. However, I couldn’t get it to work - or rather not work…

I had one object with an animation that ping-ponged between tiny and big. Another object fell onto this. No matter what I did, I couldn’t get the same trampoline effect that you get.

Thank you for testing it, PGJ! Below is another video of the same scenario, but now from the scene view so that you can see the colliders. Anything I’m doing different than you?
Every character has 3 colliders: a box collider for the legs and body, a sphere collider for the head, and a box collider (as trigger) for the hitbox.

I see, I used 2D physics, since your game looked 2D. When I redid my test with the 3D physics, I got the same problem as you. If the colliders get to overlap and the physics engine have to push the colliders apart, there is a significant amount of force created, which results in the top object being flung up into the air.

I’m not sure how to fix this. Increasing the drag, makes it a bit better. But, then you have to take the drag into account for all other movements. It’s probably easier to have your scripts cap the force to a maximum value.

1 Like

So, I guess it’s not possible to prevent colliders from overlapping?
In that case, then your suggestion to cap the maximum value oncolliderexit sounds like the best way to deal with this issue. Is there any way to know how much force is created from the colliders overlap? That would help me write up a better script for this :slight_smile:

Thank you! Really appreciate your time and help :slight_smile:

I guess the easiest way is to Debug.Log the RigidBody.velocity and then pause the game and frame step until you get to the problematic collision.

BTW: Why are you using the 3D physics? Aren’t your game objects 2D?

Well, for now I’ve just clamped the max velocity if the collision was with another character and the other character was directly below. Doesn’t feel like a very clean solution just yet, though.

Not sure why I’m using 3D, to be honest. It just seemed simpeler and more flexible at the time. If 2D physics solves this problem though, then maybe I should consider switching. Thanks for the suggestion :slight_smile: