- Home /
Precise animation control
I have a really basic animation controller setup with character being able to stay idle, run and jump. It's all controlled with two bools: Move, and Jump. I can easily control execution of the animations, but I don't know how to control them precisely.
What I mean is that when I for example introduce the jump and then start playing and continously jumping, the animation will soon fall out of synchronization with the player avatar, and the jumping animation will end and loop during middle of the jump. Also because of this, sometimes when continously jumping and moving, a running animation will play for about half a second during the jump.
My question(s) is: How to get a proper grip on animation control and fix these issues? As far as I understand, the animation isn't fully synchronized with the physics, but instead of trying to match the animation and jump time can I just somehow absolutely force the animation to be at 0 time everytime I start jumping? Are there any tips or proper handling techniques to prevent this kind of behaviour?
Answer by UltraSage · Oct 28, 2019 at 04:54 PM
So, I have found solution to my problem. Adding it couple of days late, but It'd be nice to close the question with the definitive answer;
Manipulating the transition did not work the way I wanted. Whenever movement button was pressed while jumping animation was over 50% done, the avatar would either play the running animation or freeze for about half a second. Disabling exit time would often result in running animation playing when character was still in mid air.
What fixed the jumping issue was the Animator.Play() function along with some intelligent movement handling, which let me force jump animation to be played from frame 0 whenever player starts jumping, and force idle animation whenever player is supposed to land without any momentum and running right after. This works for me, because the jumping animation doesn't look unnatural when played instantly from any given state. And it's almost perfectly synchronized with the physics. To estimate what state the animation is in I used animation events system.
With those two utilities I am able to get the control I wanted whenever the stock mecanim controls fail me due to weird transitions or something else.
Answer by Pangamini · Oct 21, 2019 at 10:39 AM
You can control the exact time position of the animation state. Select your animation State, tick "Normalized Time" and then you'll have an option to fill in the float parameter which will control the position of the animation clip when this state is playing. This means that you'll be responsible to increment this value over time using animator.SetFloat().
Optionally you could construct your own 'animator' using the playables framework, but that's much more work
Another option would be to have a transition to "Jump" from "Any State", including self (transition to self) perhaps also allowing the transition to interrupt other transitions
That's an interesting approach, I was not aware of "normalized time" functionality. I have it already solved, but that sounds like an approach that could work for me.
Answer by Arshww · Oct 18, 2019 at 03:41 AM
Hi @UltraSage, have you tried unchecking the Has Exit Time property? otherwhise, for example, if you are running and then jump, the Jump animation will wait until running animation ends: click those white arrows and try unchecking, you can read more about it here: Animation Transitions.
Has Exit Time : Exit Time is a special transition that doesn’t rely on a parameter. Instead, it relies on the normalized time of the state. Check to make the transition happen at the specific time specified in Exit Time.
Plus, i suggest you to link the Jump animation to a trigger instead of a bool
Yes, I have. That was the first thing I did. Unfortunately it didn't happen. Could you elaborate on advantages of using trigger ins$$anonymous$$d of bool in this case?
Answer by suIly · Oct 20, 2019 at 04:47 PM
Uncheck Exit Time and set the transition duration to 0
Unfortunately this did not give me the result I wanted.
Your answer
Follow this Question
Related Questions
How can I change my AnimatorState instantly? 1 Answer
16 identical Mecanim Animator errors....why? 2 Answers
Is posible to make an universal transition tree for many GameObjects? 1 Answer
Play one animation after finishing another animation using bool variable. 0 Answers
Controlling an Animation's playback through the Animator Component? 0 Answers