What is the "standard" way of making avoidable obstacles in 2D in real time?

What would be the recommended way of adding static body obstacles in real time that are avoidable by navigation agents?

In courses they advice to make a “hole” in navigation region around an object that navigation agent is suppose to go around (and add some extra margin to avoid being stuck at corners).

But what If I have to add some, let’s say, boxes or walls during the game? The nav agents will run into it and probably get stuck, if it’s on their way.

I tried to use NavigationObstacle2D on the added bodies but it didn’t work as I needed. Bots were still running into the bodies.

Navigation agents have two non-exclusive modes. A* and avoidance. NavigationObstacle only works for agents that use avoidance. The way I did it in my game is changing the traversal cost of the navigation region where the obstacle is to be rather high. That way I don’t need avoidance, but it need use of the NavigationServer which is a bit confusing to use and has no Editor widgets, it’s a low-level class.

So either figure out how to change the cost of regions if that suits your game, or figure out how avoidance works in nav agents.

If you place static physics collision you always want to change / rebake the navigation mesh around them.

If you do not change the navigation mesh all the navigation paths will still go through the collision. There is only so much the avoidance or the region cost can do about that when the navigation paths still all insist on moving inside the collision. That new object does not exist in the navigation system if it is not baked into the navigation mesh.

What do you mean by cost of regions exactly? Haven’t heard about this concept :frowning:

Yes, that’s what I meant in my second sentence of the question.

But can I do this when the game is already running?

Regions have a cost for entering and a cost for traveling that is factored in when using A* navigation. You can set it with this method: NavigationServer2D — Godot Engine (stable) documentation in English

1 Like

I see, I think this seems the best way! Thanks

using A* navigation