Navmesh Obstacle

If I place a NavMesh obstacle on a box that is instanced in the scenario, how can I prevent the enemy AI as an agent from stopping following the player when they jump over the box that is outside the NavMesh?

could you please share some screenshots? I can’t understand it



You put the NavMesh Obstacle component on the object so that the enemy AI cannot pass through it and can flip it over, but if the player stands on top of it, the enemy AI stops without doing anything.

i think it’s because they themselves cannot jump; what exactly are you trying to do? are they trying to get to the closest spot to the player that doesn’t phase through/is not inside obstacles or the player itself?

it is a game where every round these upgrade boxes appear with the navmesh obstacle so that the enemy ai can get over the obstacle but the problem i have is that if the player stands on top of the boxes the enemy ai stops following him and stays still and doesn’t even go to the closest place where the player is. i don’t know how to fix that the enemy ai stops suddenly until the player gets off the box. And the enemy ai can’t jump because it’s not inside the navmesh.

so these boxes periodically appear and they can navigate on top of it unless the player is standing on it? maybe this will help:

Vector3 destinationAi;
//the success variable can be removed
bool success = NavMesh.SamplePosition(playerPos, out destinationAi, 5f, NavMesh.AllAreas);
1 Like

No the enemy ai can’t navigate through the boxes since they are outside the navmesh and I would have to bake the navmesh every round the boxes appear so the enemy ai could walk over them, which I think would affect overall performance. The general problem is that when putting the obstacle component the enemy ai stops immediately and does nothing when the player stands on top of these boxes.


press the open agent settings then modify the step height to the height of the box

//make sure you have a reference to the gameobject that contains the NavMeshSurface component
public GameObject navmeshcontainer;

//other code

generatebox(); //your function that generates the box

NavMeshSurface navmesh = navmeshcontainer.GetComponent<NavMeshSurface>();
navmesh.Bake();

tell me if it works
(it has to bake every time i have no idea how to do it more efficiently)
(maybe you can use offmeshlink)

1 Like

Ok, I think your solution can work on static objects that appear on the stage, but for objects that have a rigidbody and which can move position, such as an explosive barrel, I don’t think it can work since the position in the navmesh would not be updated frequently, but thanks for the solutions anyway.

maybe this project by Aron will help: A* Pathfinding Project

after a month of contemplating my past mistakes, the “proper” solution to this problem is adding a navmesh obstacle component to the objects, and turn on carve.

I tried that and when the enemies were on top of the object they stopped moving because they did not detect the player since they were outside the navmesh, but oh well, it doesn’t matter. I’m already working on another project, thanks anyway.