NS-23: Skip move_and_slide when idle on floor (stop rest jitter)
Zero-velocity move_and_slide each physics tick still reapplies floor snap and collision, which often reads as vibration. If there is no walk goal (or we just arrived), velocity is zero, and is_on_floor(), return early.pull/23/head
parent
6c73557c3b
commit
39b4760270
|
|
@ -7,6 +7,9 @@ extends CharacterBody3D
|
||||||
## distance, bounds) is server MoveCommand only — not reimplemented here.
|
## distance, bounds) is server MoveCommand only — not reimplemented here.
|
||||||
##
|
##
|
||||||
## Nav detours except when goal Y is below us: then xz toward goal (waypoints sit under bump rims).
|
## Nav detours except when goal Y is below us: then xz toward goal (waypoints sit under bump rims).
|
||||||
|
##
|
||||||
|
## Idle: skip `move_and_slide()` when on floor and velocity is zero — repeated slide + floor snap
|
||||||
|
## causes visible micro-vibration at rest.
|
||||||
|
|
||||||
const MOVE_SPEED: float = 5.0
|
const MOVE_SPEED: float = 5.0
|
||||||
const ARRIVE_EPS: float = 0.35
|
const ARRIVE_EPS: float = 0.35
|
||||||
|
|
@ -54,9 +57,15 @@ func _set_horizontal_velocity_toward(point: Vector3) -> void:
|
||||||
velocity.y = 0.0
|
velocity.y = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
func _skip_move_when_idle_on_floor() -> bool:
|
||||||
|
return is_on_floor() and velocity.length_squared() < 1e-12
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
if not _has_walk_goal:
|
if not _has_walk_goal:
|
||||||
velocity = Vector3.ZERO
|
velocity = Vector3.ZERO
|
||||||
|
if _skip_move_when_idle_on_floor():
|
||||||
|
return
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -67,6 +76,8 @@ func _physics_process(_delta: float) -> void:
|
||||||
velocity = Vector3.ZERO
|
velocity = Vector3.ZERO
|
||||||
_has_walk_goal = false
|
_has_walk_goal = false
|
||||||
_nav_agent.set_target_position(global_position)
|
_nav_agent.set_target_position(global_position)
|
||||||
|
if _skip_move_when_idle_on_floor():
|
||||||
|
return
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue