[Mecanim] Animation and rotation

Hello,

I want to turn my character with an animation in Mecanim.

I have a character with an animation “idle”, and animation “turnLeft”, “turnRight” and “walkForward”. I coded a controllerScript to modify the Direction parameters in my animator. And depending on this direction, the animation “turnRight” or “turnLeft” is launched.

The animations are working well, but once the animation is finished the character go back to its initial rotation.

For exemple :

The character start in the idle state. (orientation of 0 degres, looking north)

I pressed the left arrow, the “turnLeft” animation is launched. As long as the key is pressed, the character has an orientation of 90 degres (facing west)

I release the key, the character go back to the idle state. (looking north)

Is there a way to apply the rotation definitively? Or should I code a script that change the transform rotation of the character depending on the direction?

Thanks a lot.

Take a look at: Unity - Scripting API: Animator.rootRotation

That might be what you want.

Thanks for your answer juliobds, I didn’t not that the animator also as a rotation.

But I find it weird that when I use a walk forward animation, the animation moves the gameobject. Without needing a script to change the position of the transform. Is it not possible to do the same with a rotation?

It works the exact same way as the turn animation. I start with an idle state when I press the up arrow, the speed incrase, and when sufficient the state “WalkForward” is activated, the animation is launched and the character moves as a long as I keep the up arrow pressed.

Maybe my animation is not well calibrated?

Thanks for your help.