Search Unity

Question turn character animation with script

Discussion in 'Animation' started by pappalardodd, Jun 27, 2020.

  1. pappalardodd

    pappalardodd

    Joined:
    Apr 13, 2020
    Posts:
    96
    I have a character walking in the direction it rotates, and I calculated the rotation angle between the character and the direction it should rotate.

    Code (CSharp):
    1. transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * speedRotation);
    2.  
    3. float rotationAngle = Quaternion.Angle(transform.rotation, targetRotation);
    I would like to understand how to insert character rotation animations of 90 and 180 degrees without using root motion but scripts.

    Unfortunately, I tried to do this using only the animator controller but it didn't work. I set rotationAngle as float in the animator and inserted the animation when rotationAngle is 180.
    The animation works but before the character is activated it rotates normally with its script and the animation starts in the wrong direction.
    Can anyone give advice on how to insert animations in which the character rotates 90 or 180 degrees ..?
    Maybe it's possible to put on some cases transform.rotation = (animation rotation) in order to make the character rotate only through animation for that specific occasion?
    Or should I abandon the current rotation method and use another one?