void UpdateFollowTargetBehaviour()
{
if( followTarget == null )
return;
characterActions.Reset();
NavMesh.CalculatePath( transform.position , followTarget.position , NavMesh.AllAreas , navMeshPath );
// ---> Uncomment to see the path drawn in the editor <----
// #if UNTIY_EDITOR
// for( int i = 0 ; i < navMeshPath.corners.Length - 1 ; i++ )
// {
// Debug.DrawLine( navMeshPath.corners[i] , navMeshPath.corners[i + 1] , Color.red);
// }
// #endif
if( navMeshPath.corners.Length < 2 )
return;
Vector3 path = navMeshPath.corners[1] - navMeshPath.corners[0];
bool isDirectPath = navMeshPath.corners.Length == 2;
if( isDirectPath && path.magnitude <= reachDistance )
{
return;
}
if( navMeshPath.corners.Length > 1 )
{
Vector3 inputXZ = Vector3.ProjectOnPlane( navMeshPath.corners[1] - navMeshPath.corners[0] , transform.up ).normalized;
// from XZ to XY
Vector3 localInputXZ = transform.InverseTransformVector( inputXZ );
float x = localInputXZ.x;
float y = localInputXZ.z;
Vector2 inputXY = (new Vector2( x , y )).normalized;
characterActions.inputAxes.axesValue = inputXY;
}
}