godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.25k stars 21.04k forks source link

Creating obstacles through NavigationServer2D does not work #97939

Open nezvers opened 1 week ago

nezvers commented 1 week ago

Tested versions

Reproducible 4.3

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.5186) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

Issue description

# for reproduction using drawn line for vertices
extends Line2D

## TileMapLayer for creating obstacle tiles
@export var tilemap_layer:TileMapLayer
## Obstacle's Navigation layer
@export_flags_2d_navigation var obstacle_layer:int

var obstacle_rid:RID

func _ready() -> void:
    var _navigation_rid:RID = tilemap_layer.get_navigation_map()

    obstacle_rid = NavigationServer2D.obstacle_create()
    NavigationServer2D.obstacle_set_map(obstacle_rid, _navigation_rid)
    NavigationServer2D.obstacle_set_avoidance_layers(obstacle_rid, obstacle_layer)
    NavigationServer2D.obstacle_set_position(obstacle_rid, global_position)
    # use drawn points for vertices (Counter-clock for repel as documented)
    NavigationServer2D.obstacle_set_vertices(obstacle_rid, points)
    NavigationServer2D.obstacle_set_avoidance_enabled(obstacle_rid, true)
    NavigationServer2D.obstacle_set_paused(obstacle_rid, false)

    NavigationServer2D.map_force_update(_navigation_rid)

func _exit_tree() -> void:
    NavigationServer2D.free_rid(obstacle_rid)

NavigationServer2D returns that it has registered obstacle RID, but debug drawing doesn't look like something was changed. NavigationAgent2D still gives a path through the obstacle place with enabled avoidance.

Steps to reproduce

Minimal reproduction project (MRP)

navigation_obstacles.zip

smix8 commented 1 week ago

NavigationServer2D returns that it has registered obstacle RID, but debug drawing doesn't look like something was changed.

Debug is drawn by nodes. If you dont use nodes but the server directly you have no debug visuals and need to draw your own debug.

NavigationAgent2D still gives a path through the obstacle place with enabled avoidance.

Avoidance and pathfinding are different systems. RVO Avoidance works with velocities, it has nothing to do with the navigation mesh surface based pathfinding.

The obstacle that was created here would affect the avoidance velocity, it will do nothing for pathfinding. The only thing that affects pathfinding is the navigation mesh surface. The obstacle shape can be baked to the navigation mesh surface when affect_navigation_mesh=true is enabled but it still needs to be baked with the navigation mesh like any other object that should affect the pathfinding.

nezvers commented 1 week ago

That sounds wrong.

If NavigationServer doesn't create an actual obstacle than what does?