Head rotation, looking at next way point?

I have been fighting with this for days and thought it was time to ask for help.

I have a bunch of animals which are using the RichAI script as well as the RVOController script on a nav mesh to path around the world. This works great with A* and the avoidance looks good, but I would like to turn their heads in the direction they are turning when walking around corners.

My first thought was using mecAnim and blending to a turning walk cycle. I set up the animation and added float “Direction” var to blend the turn but then couldn’t find a way to get this information from RichAI script to turn it?

My second thought was to simply turn the head to face the next way point, however when I tried to get the next waypoint from the RichAI script, the position was up in the air and not in the correct place at all?

Can anyone suggest a solution to either of these problems?

Personally I would use something like AimIK, if you have the FinalIK component or similar.

That said, in terms of looking at the direction they are going to go, I’d find the point and then just set the y to be the same as your animal’s head Y, or something along those lines. Best case your next path Y is going to be too far down anyhow, since normally those would be on the ground where the animal walks. So in any case you’re going to need to adjust how the y tilt is for the axis. Before you do LookAt or similar, just take the “target” point and set the y equal to something around the height of your head bone.

Thanks for the reply.

I think I will just go for head rotation for now, however, how do I get the next waypoint position from the RichAI script ? If I get the public Vector3 NextWaypoint varible, it’s the wrong position and is up in the air a long way off?

That I’m not sure about.

Ah, not sure why, but it looks like the NextWayPoint variable acts like it’s 2D? If I move the .Y into the .Z of my vector3 position, I can get the correct placement of the next way point in 2D, which is all I need for head rotation.


The NextWaypoint property is as you have figured out the waypoint that the AI is currently moving towards.
This is called “steeringTarget” in the beta versions. It should be in world space, not a 2D variable, but I think by mistake it has ended up being a 2D property in some version (possibly an earlier beta). Maybe you can try to upgrade?

Thanks for the reply.

I will update at some point this weekend and report back.