Problem with Unity animator controller priority against scripts


When making the enemies ai and workng on the player movment, the animations were having problems with the actual movment, where directly modifying the model's position or velocity while playing the animation can cause the models look like they are sliding, which is not good for player's visual experience. 

After doing some researches and testing, I found a solution for the problem. When importing a human-like model, I turn on the humanoid animation type, and create avatar for the animations, and then I can click on "Apply Root Motion" option in the animator controller. With that the model only moves when the animation moves.

But there are also some problems coming with that. The first one is that some times the animation is having a Y axis movment or probably rotations that can cause unexpected movment, a simple solution to that is to bake the unwanted movment in to pose by clicking the "Bake Into Pose" option in the animation clips. Another problem is sometimes I want my model to be able to do a jump attack or a rolling movement regardless of the animation, but the animator has higher proirity over the scripts so that any force applied on it will be overwritten by the animator. The solution I used for that is in the scipt, when start doing movements, I turn off the apply to root motion option on the animator, and when the animation finished or a timer has reached, I turn the apply to root motion back so that the animator regain the control of the movement.

Author: Zeyuan Song

Posted on 03/22/2024

Get Suits of the Abyss

Leave a comment

Log in with itch.io to leave a comment.