I’m trying to use the NavigationObstacle2D in my project. The NavigationObstacle2D do block the agent from walking into that zone but the agent don’t walk around it.
(I know I can cut a hole in the mesh but this is a test for eventually make moving obstacle. Moreover, I’ve all the tutorial and guide I could find about this. If you see a solution on the internet I’ve may have missed, please let me know)
Here’s the code for I’m using for navigation and the scene structure:
using Godot;
public partial class Enemy : CharacterBody2D
{
public static Player player;
[Export] NavigationAgent2D NavigationAgent;
public override void _Process(double delta) {
NavigationAgent.TargetPosition = player.GlobalPosition;
if (NavigationAgent.IsNavigationFinished()) return;
NavigationAgent.Velocity = (NavigationAgent.GetNextPathPosition() - GlobalPosition).Normalized() * 1000;
}
public void OnVelocityComputed(Vector2 vector) {
Velocity = vector;
MoveAndSlide();
}
}
Yes, I’ve checked avoidance_enabled to true. avoidance_layers and avoidance_mask in NavigationAgent2D and NavigationRegion2D both have the same bit mask as well.
I’ve tried every setting I see in the inspector, as I’m struggle to fix this problem and communicate at delayed interval like this is unideal. Here’s my minimum project that reproduce the problem. Hopefully you can find some time and help me out.
I tried my own project and well when you reach an avoidance obstacle the path doesnt get recalculated, instead you are moving in somewhat random directions, hoping the obstacle will get out of the way
Im afraid thats how its supposed to be. You would have to calculate your own avoidance path if you want different behaviour. Avoidance should only be used when the object is moving a lot so baking the navmesh would be to expensive. If your obstacle is moving then the current implementation shouldnt be too bad
But in my project, the agent still go the same path whether the obstacle is there or not. Shouldn’t the agent go around if an obstacle is on the way? I saw some tutorial on Youtube and their implementation have the agent always avoid the obstacle mesh.
Note that this got changed in Godot 4.3 and the obstacle has an option to bake to the navigation mesh in that version. You still need to rebake your navigation mesh regardless.
I just looked in your original message and you set the velocity in your process function. Try to implement what the guy implemented in the video, then it should work