@@ -505,7 +505,7 @@ The following sections provides script templates for nodes commonly used with Na
505
505
506
506
@export var movement_speed: float = 4.0
507
507
@onready var navigation_agent: NavigationAgent3D = get_node("NavigationAgent3D")
508
- var movement_delta : float
508
+ var physics_delta : float
509
509
510
510
func _ready() -> void:
511
511
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
514
514
navigation_agent.set_target_position(movement_target)
515
515
516
516
func _physics_process(delta):
517
+ # Save the delta for use in _on_velocity_computed.
518
+ physics_delta = delta
517
519
# Do not query when the map has never synchronized and is empty.
518
520
if NavigationServer3D.map_get_iteration_id(navigation_agent.get_navigation_map()) == 0:
519
521
return
520
522
if navigation_agent.is_navigation_finished():
521
523
return
522
524
523
- movement_delta = movement_speed * delta
524
525
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
526
527
if navigation_agent.avoidance_enabled:
527
528
navigation_agent.set_velocity(new_velocity)
528
529
else:
529
530
_on_velocity_computed(new_velocity)
530
531
531
532
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 )
533
534
534
535
.. code-tab :: gdscript CharacterBody3D
535
536
0 commit comments