Skip to content

Commit 237adb5

Browse files
committed
fix NavigationAgent3D template for Node3D
fixes #11088
1 parent 6aba137 commit 237adb5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tutorials/navigation/navigation_using_navigationagents.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ The following sections provides script templates for nodes commonly used with Na
505505

506506
@export var movement_speed: float = 4.0
507507
@onready var navigation_agent: NavigationAgent3D = get_node("NavigationAgent3D")
508-
var movement_delta: float
508+
var physics_delta: float
509509

510510
func _ready() -> void:
511511
navigation_agent.velocity_computed.connect(Callable(_on_velocity_computed))
@@ -514,22 +514,23 @@ The following sections provides script templates for nodes commonly used with Na
514514
navigation_agent.set_target_position(movement_target)
515515

516516
func _physics_process(delta):
517+
# save the delta for use in _on_velocity_computed
518+
physics_delta = delta
517519
# Do not query when the map has never synchronized and is empty.
518520
if NavigationServer3D.map_get_iteration_id(navigation_agent.get_navigation_map()) == 0:
519521
return
520522
if navigation_agent.is_navigation_finished():
521523
return
522524

523-
movement_delta = movement_speed * delta
524525
var next_path_position: Vector3 = navigation_agent.get_next_path_position()
525-
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_delta
526+
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
526527
if navigation_agent.avoidance_enabled:
527528
navigation_agent.set_velocity(new_velocity)
528529
else:
529530
_on_velocity_computed(new_velocity)
530531

531532
func _on_velocity_computed(safe_velocity: Vector3) -> void:
532-
global_position = global_position.move_toward(global_position + safe_velocity, movement_delta)
533+
global_position = global_position.move_toward(global_position + safe_velocity, physics_delta * movement_speed)
533534

534535
.. code-tab:: gdscript CharacterBody3D
535536

0 commit comments

Comments
 (0)