I did some research but wasn’t able to find an answer to the question of matching animation with the included AIPath script.
What I have is a character that’s moving quickly. When it’s making turns, I’d like the character to lean its body into the turn and have its joints change appropriately to match the lean.
The animation is already set up, and all I have to do is feed the animation a value between -1 and 1 to represent the turning/rotating. -1 means the sharpest turn the character can make to its left, and 1 means the sharpest turn it can make to its right.
Which values do I read from AIPath to do this and how would I go about turning it into a float value between -1 and 1?
I think the easiest way is to track the rotation speed of the Transform component directly. Something like this would work:
float angularSpeed = 0;
float previousRotation = 0;
void Update () {
// Calculate how much the object has rotated since the last frame
var delta = Mathf.DeltaAngle(previousRotation, transform.eulerAngles.y);
previousRotation = transform.eulerAngles.y;
// Add some smoothing
anglularSpeed = Mathf.Lerp(angularSpeed, delta / Time.deltaTime, 4 * Time.deltaTime);
// Convert the angular speed to a value between -1 and 1 approximately
// You likely need to tweak the constant '90'
var leaningParameter = angularSpeed / 90;
}