Problems with moving an object on a 3d navigation agent

Godot Version

4.2.1 stable

Question

Please save me
The character does not move in the desired direction, he just stands, although the velocity comes with a value different from 0. I created a Navigation Region3d for the map. I tried this option according to the documentation, the object just stands still.

extends CharacterBody3D

@export var movement_speed = 10

var navigation_agent: NavigationAgent3D

func _ready():
	navigation_agent = $NavigationAgent3D

func set_movement_target(movement_target: Vector3):
	navigation_agent.set_target_position(movement_target)

func _physics_process(delta):
	await get_tree().process_frame
		
	if navigation_agent.is_navigation_finished():
		return

	var next_path_position: Vector3 = navigation_agent.get_next_path_position()
	var desired_velocity = (next_path_position - global_position).normalized() * movement_speed
	
	navigation_agent.set_velocity(desired_velocity)
	
	velocity = desired_velocity
	move_and_slide()

image

I tried this option according to the documentation, the object just stands still.

The documentation examples all work so look at problems in your scene setup.

E.g. a physics collision setup that is blocking the agent parent global_position from getting close enough to the next path point to advance the path is a common culprit.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.