How do you use Unity's Animator when dealing with animation curve values that have a default value and the default value causes jumps in animation transitions?

I have a bit of a complex problem with updating the collider from animator properties. Here's an example:

I have a player character animator controller that has stand/crouch/prone states. Th capsule collider's height/radius/center can be controlled from animation curves. So for example I have these three properties in my mecanim animator controller with default values:

ColliderHeightMult = 1.0
ColliderRadiusMult = 1.0
ColliderCenterOffset = 0.0

If for example the player goes crouched, the ColliderHeightMult and ColliderRadiusMult are taken from the crouch animation's curve so that the collider scales down in size.

This is all good so far but the trouble starts with the prone posture because for that the direction of the collider needs to be changed to be horizontal (collider.Direction = 2).

Now if the player was prone and the collider was horizontal and he goes back to crouched or standing, the collider direction is changed back to vertical (collider.Direction = 1). This however causes the collider to extend into the ground for a moment which causes the player to jump up for a moment or messes up my ground/airborne check.

The solution I found for this is to check if the target height/radius/center was reached and only then change the collider direction. This changes the collider direction only at the point when it's high enough in the air to not extend into the ground.

But here's the issue: At every animation state change the ColliderHeightMult is back to 1.0 and my height mult check succeeds already at that point causing the direction to be changed instantly, ruining my solution.

Does anyone have an idea how to tackle this whole problem (maybe in a different way)? Note that checking IsInTransition() won't help and actually I would prefer to have it smoothly adapt the collider size even during state transition.

  • \$\begingroup\$ Would it be feasible to include two colliders, one horizontal and one vertical, and enable/disable them when switching states so the vertical collider doesn't need to transition in and out of the prone position? \$\endgroup\$ – DMGregory Nov 7 '15 at 14:54
  • \$\begingroup\$ @DMGregory Interesting idea! Might help but I think it should definitely be doable with only one collider. I'd prefer not to throw in another collider which I think would make matters more complicated later on (when I want to take care of ragdoll collider integration for example). \$\endgroup\$ – BadmintonCat Nov 7 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.