Understanding Godot Navigation Obstacle node

117 Views Asked by At

This question is 3d based.

So I have been able to build a click and move system in godot with the NavigationRegion3D node with mesh instances as children. World Hierarchy here

Apart from that I have two other nodes, the NavigationAgent3D node and the NavigationObstacle3D node for pathfinding and path obstacle respectively.

The NavigationAgent3D node works as expected on the region with pre-baked navigation data(no obstacle used). The code for agent movement is as :

extends Node3D

@onready var NavigationAgent:NavigationAgent3D = get_node("NavigationAgent3D")

var movespeed = 1
var movedelta
var enabled = false
var n = Vector3(0, 1, 0)

func _ready():
    var agentrid = NavigationAgent.get_rid()
    #NavigationServer3D.agent_set_avoidance_enabled(agentrid,true)
    NavigationServer3D.agent_set_avoidance_callback(agentrid,Callable(self,"_avoidance_done"))
    movedelta = movespeed
    var timer = Timer.new()
    add_child(timer)
    timer.wait_time = 2
    timer.autostart = true
    timer.timeout.connect(timerDone)
    timer.start()

func _physics_process(delta):
    if !enabled:
        return
    
    movedelta = movespeed * delta 
    
    var target = NavigationAgent.get_next_path_position()

    # Calculate the velocity.
    var vel = global_position.direction_to(target) * movedelta
    
    # Tell the agent the velocity.
    NavigationAgent.set_velocity(vel)

func timerDone():
    enabled = true
    NavigationAgent.set_target_position(Vector3(0,0,0))

func _on_navigation_agent_3d_velocity_computed(safe_velocity):
    global_position = global_position.move_toward(global_position+safe_velocity,movedelta)

func _avoidance_done(safe_velocity):
    global_position = global_position.move_toward(global_position+safe_velocity,movedelta)

I have modified the original code to start after a two second delay. As said previously the navigation node works as expected. The problem is that the node behaves unexpectedly when I place the obstacle dynamically in the scene.

I have enabled avoidance on both the nodes and setup the radii for both the nodes. It would help me a lot if anyone can help me to understand the Godot engines RVO aviodance(?) and/or help setup a small project for the same.

Thank you.

Agent inspector here

Obstacle inspector here

0

There are 0 best solutions below