Search code examples
animationunity-game-enginetransitionunity3d-2dtools

Make mecanim transition after a delay in Unity3D (2D mode)


I'm using Unity's Animator to animate my character, I want an animation to start only if it lasts long enough.

For example: sometimes if my character goes on the ground and there's a little something on the way it makes my character ascend for a frame or two, but my onGround parameter of my animator still detects the change an make my character animating the Flying animation.

So in this case I want my animation to start only after a short delay like 0.1 sec, and only if the onGround parameter is still false, to avoid these little glitches.

Is there an easy way doing this? Or should I manipulate it from script? If so, how?


Solution

  • As a solution I'm using a float variable with the name offGroundTime. I set the value in every tick, increase it with Time.deltaTime if my onGround variable is false and set it to 0 if it's true. If the offGroundTime is bigger than 0.2, I turn on the flying animation, if it's lower, I turn on the idle animation.