38 lines
932 B
GDScript
38 lines
932 B
GDScript
extends CharacterBody3D
|
|
|
|
## NS-14: click-to-move using horizontal steering + move_and_slide (not NavigationAgent3D).
|
|
## Obstacles are handled by physics sliding, not pathfinding — see client README.
|
|
|
|
const MOVE_SPEED: float = 5.0
|
|
const ARRIVE_EPS: float = 0.35
|
|
|
|
var _goal: Vector3
|
|
|
|
|
|
func _ready() -> void:
|
|
_goal = global_position
|
|
|
|
|
|
|
|
func set_move_goal(world_pos: Vector3) -> void:
|
|
_goal = world_pos
|
|
_goal.y = global_position.y
|
|
|
|
|
|
## NS-16: snap to authoritative server position; clears velocity so `move_and_slide` does not fight the sync.
|
|
func snap_to_server(world_pos: Vector3) -> void:
|
|
global_position = world_pos
|
|
velocity = Vector3.ZERO
|
|
_goal = world_pos
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
var to_goal: Vector3 = _goal - global_position
|
|
to_goal.y = 0.0
|
|
if to_goal.length() <= ARRIVE_EPS:
|
|
velocity = Vector3.ZERO
|
|
else:
|
|
velocity = to_goal.normalized() * MOVE_SPEED
|
|
velocity.y = 0.0
|
|
move_and_slide()
|