My NavAgent is stopping quitting before it reaches its end goal

Godot Version

4.2.2

Question

I’m trying to figure out how to use navigation meshes and agents, and while I did get the agent to move it still has some quirks I don’t like.

  1. it reaches its destination but it jitters.

  2. It stops just short of reaching it’s end goal.

Here’s 1

extends CharacterBody3D

@onready var navigation_agent_3d = $NavigationAgent3D

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("move_npc"):
		var random_position := Vector3.ZERO
		random_position.z = randf_range(-5.0, 5.0)
		random_position.x = randf_range(-5.0, 5.0)
		navigation_agent_3d.target_position = random_position
		
func _physics_process(delta: float) -> void:
	var destination = navigation_agent_3d.get_next_path_position()
	var local_destination = destination - global_position
	var direction = local_destination.normalized()
	
	velocity = direction * 5.0

move_and_slide()

here’s 2

extends CharacterBody3D

@onready var navigation_agent_3d = $NavigationAgent3D

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("move_npc"):
		var random_position := Vector3.ZERO
		random_position.z = randf_range(-5.0, 5.0)
		random_position.x = randf_range(-5.0, 5.0)
		navigation_agent_3d.target_position = random_position
		
func _physics_process(delta: float) -> void:
	if navigation_agent_3d.is_navigation_finished():
		velocity = Vector3.ZERO
	else:
		var destination = navigation_agent_3d.get_next_path_position()
		var local_destination = destination - global_position
		var direction = local_destination.normalized()
		velocity = direction * 5.0
		move_and_slide()

Nevermind, I’m an idiot.

I had to change the path desired property under Navagent to get it to stop on the point…

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