Using one animation in different orientations

Hello, I am making a game where the player runs and when he swipes the screen or hits left/right arrow on a keyboard, the player turns.

I could use transform.Rotate(0,90,0) but I want to make it kinda smooth, so I want to use an animation.

The problem is, that if I create an animation with two keyframes: transform.rotation.y = 0 and transform.rotation.y = 90, this happens:

Player turns right for the first time, the animation plays and now the y rotation is equal to 90.

Player turns right once more, but the animation doesn’t play from 90 to 180, but from 0 to 90 again.

How do I fix this?


I am not an English speaker, so please correct this question if necessary.
Thank you, imilanspinka

Either make an animation for each possible rotation if you want to stay with doing turning by animation.

What I recommend tho is to not have an animation handle the turning. Instead write some code that rotates the player accordingly and you can rotate in a smooth way.

transform.rotation.eulerAngles = Vector3.SmoothDamp(transform.rotation.eulerAngles, targetRotation,
		                             ref SomeVector, timeTurnShouldTake);

targetRotation in this case would be something like (0,transform.rotation.eulerAngles.y+90,0).

Something like that would work and have smooth rotation change when done in update.

For further information on SmoothDamp look at the Docs