Search Unity

Question Navmesh agent running away then towards destination

Discussion in 'Navigation' started by Robster95, Feb 4, 2024.

  1. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I am trying to work on a retreat function for an enemy in my game. I am testing it right now where I click on the ground with my mouse to find a position around my creature and then have the enemy run in the opposite direction.

    The problem that I am having is that in my scene I have an area with NavMeshLinks but they're a good distance away from the creature. Whenever I have the creature find a path to the destination for it to run away to, it runs towards the NavMeshLinks and THEN towards the destination.

    I don't understand why this is happening. I have increased the cost of the NavMeshLinks, I have baked the NavMeshSurface components and changed the cost in the Navigation window.

    I have dropped a picture to show the scene and give a little understanding.
    The blue sphere is where I clicked.
    The green sphere is the destination for the creature to run towards
    The red line is the path for the creature to take.

    The creature runs all the way to the structures on the top right just to jump over the NavMeshLinks and after it jumps over them then it runs back towards the destination.


    I am using Unity 2022.3 and using the basic NavMesh components, not any from the asset store.