Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Mecanim] Animation and rotation

Discussion in 'Scripting' started by Navezof, Apr 28, 2013.

  1. Navezof

    Navezof

    Joined:
    Dec 2, 2012
    Posts:
    22
    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.
     
  2. juliobds

    juliobds

    Joined:
    Dec 27, 2011
    Posts:
    25
  3. Navezof

    Navezof

    Joined:
    Dec 2, 2012
    Posts:
    22
    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?
    $turnleft_animation.jpg

    Thanks for your help.