NS-23: Revert global gravity; use step-off-only descend vy
Project gravity while walking made motion worse (jitter, floor fights). Restore horizontal-only seek everywhere except the short step-down bypass, where a fixed downward speed helps clear NS-19 bump lips without affecting normal nav or idle air state.pull/23/head
parent
127e67f02b
commit
b1ce87c5cc
|
|
@ -2,8 +2,8 @@ extends CharacterBody3D
|
|||
|
||||
## NS-23: Follow server move target on walkable geometry.
|
||||
##
|
||||
## Horizontal seek sets `velocity.x`/`z` only. On floor `velocity.y` is cleared; in air project
|
||||
## gravity applies so walking off bumps/steps can descend (vy was never forced to 0 while airborne).
|
||||
## Horizontal velocity toward nav waypoint or goal; `velocity.y` stays 0 except a short **step-off**
|
||||
## nudge (see `_nav_short_step_down_use_goal_direct`) so NS-19 bumps can drop without full gravity.
|
||||
## Move **legality** is server MoveCommand only — not reimplemented here.
|
||||
##
|
||||
## Nav for detours; short local step-down (feet vs goal Y, not body origin) may bypass waypoints.
|
||||
|
|
@ -19,6 +19,8 @@ const STEP_OFF_MIN_DROP: float = 0.055
|
|||
const STEP_OFF_MAX_DROP: float = 0.24
|
||||
const STEP_OFF_MAX_HORIZ: float = 3.0
|
||||
const FLOOR_PROBE_BODY_Y_OFFSET: float = -0.55
|
||||
## Downward vy only while step-off bypass is active (not global gravity).
|
||||
const STEP_OFF_DESCEND_SPEED: float = 1.6
|
||||
## If next waypoint is within this xz of us, steer to goal (rim / underfoot waypoints).
|
||||
const NEXT_WAYPOINT_MIN_HORIZ_SQ: float = 0.01
|
||||
|
||||
|
|
@ -106,33 +108,13 @@ func _set_horizontal_velocity_toward(point: Vector3) -> void:
|
|||
var dh: Vector3 = Vector3(point.x - pos.x, 0.0, point.z - pos.z)
|
||||
if dh.length_squared() < 1e-10:
|
||||
dh = Vector3(1.0, 0.0, 0.0)
|
||||
var h: Vector3 = dh.normalized() * MOVE_SPEED
|
||||
velocity.x = h.x
|
||||
velocity.z = h.z
|
||||
velocity = dh.normalized() * MOVE_SPEED
|
||||
velocity.y = 0.0
|
||||
|
||||
|
||||
func _apply_vertical_velocity_for_floor_or_gravity(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
velocity.y = 0.0
|
||||
return
|
||||
var gmag: float = float(ProjectSettings.get_setting("physics/3d/default_gravity", 9.8))
|
||||
var gvec: Variant = ProjectSettings.get_setting(
|
||||
"physics/3d/default_gravity_vector", Vector3(0.0, -1.0, 0.0)
|
||||
)
|
||||
if gvec is Vector3:
|
||||
velocity += (gvec as Vector3) * gmag * delta
|
||||
else:
|
||||
velocity.y -= gmag * delta
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if not _has_walk_goal:
|
||||
if is_on_floor():
|
||||
velocity = Vector3.ZERO
|
||||
else:
|
||||
velocity.x = 0.0
|
||||
velocity.z = 0.0
|
||||
_apply_vertical_velocity_for_floor_or_gravity(delta)
|
||||
velocity = Vector3.ZERO
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
|
|
@ -152,13 +134,12 @@ func _physics_process(delta: float) -> void:
|
|||
var nav_map: RID = _nav_agent.get_navigation_map()
|
||||
if NavigationServer3D.map_get_iteration_id(nav_map) == 0:
|
||||
_set_horizontal_velocity_toward(_auth_walk_goal)
|
||||
_apply_vertical_velocity_for_floor_or_gravity(delta)
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
if _nav_short_step_down_use_goal_direct():
|
||||
_set_horizontal_velocity_toward(_auth_walk_goal)
|
||||
_apply_vertical_velocity_for_floor_or_gravity(delta)
|
||||
velocity.y = -STEP_OFF_DESCEND_SPEED
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
|
|
@ -174,5 +155,4 @@ func _physics_process(delta: float) -> void:
|
|||
else:
|
||||
_set_horizontal_velocity_toward(_auth_walk_goal)
|
||||
|
||||
_apply_vertical_velocity_for_floor_or_gravity(delta)
|
||||
move_and_slide()
|
||||
|
|
|
|||
Loading…
Reference in New Issue