It's useful to use a visual Debug Ray to show us the straight line from the NPC with NavMeshAgent to the current destination it is trying to navigate toward. Since this is a common thing we may wish to do for many games, it's useful to create a static method in a general-purpose class; then, the ray can be drawn with a single statement.
To use a Debug Ray to draw a source-to-destination line, follow these steps:
- Create a UsefulFunctions.cs C# script class containing the following code:
using UnityEngine;
public class UsefulFunctions : MonoBehaviour {
public static void DebugRay(Vector3 origin, Vector3 destination, Color c) {
Vector3 direction = destination - origin;
Debug.DrawRay(origin, direction, c);
}
}
- Now, add a statement at the end of the HeadForDestination() method in the ArrowNPCMovement C# script class:
using UnityEngine;
using UnityEngine.AI;
public class ArrowNPCMovement...