Search Unity

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

Discussion in 'Scripting' started by RichardsonKevin, Oct 5, 2015.

  1. RichardsonKevin

    RichardsonKevin

    Joined:
    Feb 3, 2013
    Posts:
    43
    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.

    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?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    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.