Godot Version
4.2.2
Question
Not sure if this comes across on the video. I have a basic scene, with a NavigationRegion but when I navigate around the terrain the movement jitters/slows down when the player crosses a navigation polygon. I followed the documentation Godot has here:
At first I thought it may have been something to do with how I set up my character. So I tried it with a basic CharacterBody3D with a capsule and the same problem occurs (little harder to see.)
With player:
With test:
Not sure what it could be. I’ve tried changing the navigation mesh to reduce the number of nav polygons. I have also tried tweaking the pathfinding properties of the agent in “Path Desired Distance” etc but no joy.
extends CharacterBody3D
@export var movement_speed: float = 8.0
@onready var camera: Camera3D = get_node("Camera3D")
@onready var navigation_agent: NavigationAgent3D = get_node("NavigationAgent3D")
func _ready() -> void:
navigation_agent.velocity_computed.connect(Callable(_on_velocity_computed))
func _input(event):
if event is InputEventMouseButton and event.is_action_pressed("move"):
var result = _mouse_raycast()
if !result: return
set_movement_target(result.position)
func set_movement_target(movement_target: Vector3):
navigation_agent.set_target_position(movement_target)
func _physics_process(delta):
if navigation_agent.is_navigation_finished():
return
var next_path_position: Vector3 = navigation_agent.get_next_path_position()
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
if navigation_agent.avoidance_enabled:
navigation_agent.set_velocity(new_velocity)
else:
_on_velocity_computed(new_velocity)
func _on_velocity_computed(safe_velocity: Vector3):
velocity = safe_velocity
move_and_slide()
func _mouse_raycast():
var mouse_position = get_viewport().get_mouse_position()
var from = camera.project_ray_origin(mouse_position)
var to = from + camera.project_ray_normal(mouse_position) * 1000
var space_state = get_parent().get_world_3d().direct_space_state
var params = PhysicsRayQueryParameters3D.new()
params.from = from
params.to = to
var result = space_state.intersect_ray(params)
return result