Getting float values from navmesh agent so AI plays proper strafing animation...

Hello Everyone!

I am trying to make my AI strafe using navmesh for movement and mecanim to play the animations.

I want to ai to always be aiming towards my player so I turned of UpdateRotation on the navmesh and created a function that makes it always face the player.

I have made a blend tree in mecanim using free-form Cartesian blend between two floats, velocityX and velocityZ. velocityX controls the forward and backward walking animations, velocityZ controls the strafe left and right animations.

I want him to move along the path and play the correct strafing animations while facing the player like below.

2326332--157016--Help.jpg

How would I go about getting the proper float values for velocityX and velocityZ so I can set them?
Or if anyone uses a different solution can you please help me?

I believe what you are looking for is the dot product of your enemy’s aim direction and the direction of travel.

This should give you the magnitude of the component along the AI → Destination vector (aka “VelocityX” in your local frame), and from that you can calculate the orthogonal component (aka “VelocityY”) using Pythagorean theorem.

I think that’s the values you are looking to feed into your Mecanim mixer.