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
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.