how do I make it so after a few seconds my character would do a different animation, and then go back to its previous animation? I am making an Idle animation, where after a few seconds, the character looks around to see their surroundings. If that can’t happen, then how do I slow down part of an animation?
1 Answer
1If you want to do this entirely in the animator, you can create a transition to occur after the idle animation has played some number of times.
In the above screenshot, the DefaultIdle animation will play 3 times, then transition to the SecondIdle state. There are no other transition conditions. The “Exit Time” field is the number of loops that DefaultIdle will play before transitioning to SecondIdle. The SecondIdle state has a similar transition back to DefaultIdle, but the ExitTime is 1 to play only a single time.
If you go with this approach, then any transition you have exiting the Idle state will have to be duplicated in the SecondIdle state. For example, if there is a transition to a run state when the player presses a direction, then you will need to check for that in SecondIdle as well.
Perhaps a more elegant solution could be done with sub-state machines, but I honestly don’t have the experience to help with that (Unity - Manual: Sub-State Machines)
Also note that this approach will always have the same amount of time between DefaultIdle and SecondIdle. If you want some randomness, then you’ll have to do that in scripting.
