neon-sprawl/client/scripts/player.gd

31 lines
750 B
GDScript

extends CharacterBody3D
## NS-14: drives CharacterBody3D toward NavigationAgent3D path. Client-only; not server-authoritative.
const MOVE_SPEED: float = 5.0
@onready var _nav: NavigationAgent3D = $NavigationAgent3D
func _ready() -> void:
# Map sync: avoid querying paths before the navigation map is ready.
await get_tree().physics_frame
_nav.target_position = global_position
func _physics_process(_delta: float) -> void:
if _nav.is_navigation_finished():
velocity = Vector3.ZERO
move_and_slide()
return
var next: Vector3 = _nav.get_next_path_position()
var dir: Vector3 = next - global_position
dir.y = 0.0
if dir.length() < 0.05:
velocity = Vector3.ZERO
else:
velocity = dir.normalized() * MOVE_SPEED
move_and_slide()