NS-23: Apply gravity when airborne so bump ledges are not sticky
Horizontal seek only sets vx/vz; zero vy only on floor. Use project default gravity vector when not on floor (with and without walk goal) so stepping off NS-19 bumps can fall to the lower surface instead of hanging with vy=0.pull/23/head
parent
3b4340830a
commit
127e67f02b
|
|
@ -2,9 +2,9 @@ extends CharacterBody3D
|
|||
|
||||
## NS-23: Follow server move target on walkable geometry.
|
||||
##
|
||||
## Horizontal velocity toward nav waypoint or goal only; `velocity.y` stays 0. Height along ramps
|
||||
## and steps comes from `move_and_slide` + floor_* on CharacterBody3D. Move **legality** (step,
|
||||
## distance, bounds) is server MoveCommand only — not reimplemented here.
|
||||
## 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).
|
||||
## 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.
|
||||
|
||||
|
|
@ -106,13 +106,33 @@ 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)
|
||||
velocity = dh.normalized() * MOVE_SPEED
|
||||
velocity.y = 0.0
|
||||
var h: Vector3 = dh.normalized() * MOVE_SPEED
|
||||
velocity.x = h.x
|
||||
velocity.z = h.z
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
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:
|
||||
if not _has_walk_goal:
|
||||
velocity = Vector3.ZERO
|
||||
if is_on_floor():
|
||||
velocity = Vector3.ZERO
|
||||
else:
|
||||
velocity.x = 0.0
|
||||
velocity.z = 0.0
|
||||
_apply_vertical_velocity_for_floor_or_gravity(delta)
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
|
|
@ -132,11 +152,13 @@ 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)
|
||||
move_and_slide()
|
||||
return
|
||||
|
||||
|
|
@ -152,4 +174,5 @@ 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