Remove PathFinding in Navmesh Agent

,

Hello,

I kind of dislike the pathfinding automaticaly setup with the navmesh utilisation.

Is there a way to still use a navmesh agent but to remove the pathfinding composant ?

At the moment we have this :

        //speedFraction refere to ennemy patrol fraction speed in AIController
        public void StartMoveAction(Vector3 destination, float speedFraction)
        {
            GetComponent<ActionScheduler>().StartAction(this);
            MoveTo(destination, speedFraction);
        }

        public void MoveTo(Vector3 destination, float speedFraction)
        {
            navMeshAgent.speed = maxSpeed * Mathf.Clamp01(speedFraction);
            navMeshAgent.destination = destination;
            navMeshAgent.isStopped = false;
        }

I guess i should replace the navMeshAgent.destination by something more like :

  • Draw a line between the player and the target
  • try go to there as a direct path

But a have no idea how to do that ^^’

If someone could help me on this :slight_smile:

Many thanks !

Simply put, no. The NavMeshAgent only knows how to traverse a NavMesh using pathfinding.

As long as you understand that this method will have the character attempting to move through any obstacles in it’s path… The whole idea behind a Nav Mesh is to avoid obstacles…

If you want to avoid using the NavMeshAgent, you could simply move the character towards the target location in the Update loop

The simplest way of accomplishing this:

Vector3 destination;

void Update()
{
    if(Vector3.Distance(transform.position, destination)>1.0f)
   {
       transform.Lookat(destination);
       transform.Translate(Vector3.forward * moveSpeed);
       GetComponent<Animator>().setFloat(forwardSpeed, moveSpeed);
    } else
    {
        GetComponent<Animator>().setFloat(forwardSpeed, 0);
    }
}