How to rotate a character in place using root motion aniamtions?

Hi all,

I’m trying to figure out how to rotate a character using root motion animations. I have a blend tree with a float parameter from -90 to 90. How to use a code to rotate it.

someAnimator.SetFloat("paramName", someFloatValue);

I know, But I meant something different. How to connect an AI bot’s rotation with playing its animations. A model of an enemy is rotating aiming at the player and its animations are being played.

You need to find the delta angle from the facing direction to the goal direction, then push that into the Animator so the blend tree can work.

The face direction of the AI bot? And the goal is of course the player? And the does delta angle return float?

Here’s my code:

Vector3 targetDir = playerTarget.transform.position - transform.position;
float angle = Vector3.Angle(targetDir, transform.forward);
anim.SetFloat("WalkAngle", angle);

It seems to work, but not always. I think I should do something in the Blend Tree. I have 5 animations (Turn Left 180, Turn Left 90, Idle, Turn Right 90, Turn Right 180). Thresholds: -90, -10, 0, 10, 90.

1 Like