feat: implement ground movement state with integrated jumping, sliding, and stair-stepping logic

This commit is contained in:
DottsGit
2026-06-15 15:58:16 -04:00
parent abddc0c1cc
commit 3afc213b3a
2 changed files with 30 additions and 12 deletions
+19 -7
View File
@@ -70,20 +70,32 @@ func _process(delta: float) -> void:
var sm = player.get_node_or_null("MovementStateMachine") var sm = player.get_node_or_null("MovementStateMachine")
var is_sliding = sm and sm.current_state == "slide" var is_sliding = sm and sm.current_state == "slide"
var target_bob_y = 0.0
var target_bob_x = 0.0
if player.is_on_floor() and hspeed > 1.0 and not is_sliding: if player.is_on_floor() and hspeed > 1.0 and not is_sliding:
_bob_timer += delta * params.head_bob_frequency * (hspeed / params.walk_speed) _bob_timer += delta * params.head_bob_frequency * (hspeed / params.walk_speed)
var bob_y := sin(_bob_timer) * params.head_bob_amplitude target_bob_y = sin(_bob_timer) * params.head_bob_amplitude
var bob_x := cos(_bob_timer * 0.5) * params.head_bob_amplitude * 0.5 target_bob_x = cos(_bob_timer * 0.5) * params.head_bob_amplitude * 0.5
camera.position.y = lerp(camera.position.y, bob_y, 0.3)
camera.position.x = lerp(camera.position.x, bob_x, 0.3)
else: else:
_bob_timer = 0.0 _bob_timer = 0.0
camera.position.y = lerp(camera.position.y, 0.0, 0.15)
camera.position.x = lerp(camera.position.x, 0.0, 0.15) # Smooth the head bob (using 15.0 * delta for framerate independence, roughly equivalent to lerp 0.3 at 60fps)
if not has_meta("smooth_bob_y"):
set_meta("smooth_bob_y", 0.0)
set_meta("smooth_bob_x", 0.0)
var sby = lerpf(get_meta("smooth_bob_y"), target_bob_y, 15.0 * delta)
var sbx = lerpf(get_meta("smooth_bob_x"), target_bob_x, 15.0 * delta)
set_meta("smooth_bob_y", sby)
set_meta("smooth_bob_x", sbx)
# ── Step Smoothing ───────────────────────────────────────────────────── # ── Step Smoothing ─────────────────────────────────────────────────────
_step_offset_y = lerpf(_step_offset_y, 0.0, 15.0 * delta) _step_offset_y = lerpf(_step_offset_y, 0.0, 15.0 * delta)
camera.position.y += _step_offset_y
# Apply final absolute position
camera.position.y = sby + _step_offset_y
camera.position.x = sbx
# ── Wall-run tilt ───────────────────────────────────────────────────── # ── Wall-run tilt ─────────────────────────────────────────────────────
_current_tilt = lerpf(_current_tilt, _target_tilt, 1.0 - exp(-params.wall_run_tilt_speed * delta)) _current_tilt = lerpf(_current_tilt, _target_tilt, 1.0 - exp(-params.wall_run_tilt_speed * delta))
+11 -5
View File
@@ -101,9 +101,15 @@ func update(delta: float) -> void:
var space_state = player.get_world_3d().direct_space_state var space_state = player.get_world_3d().direct_space_state
var feet_y = player.global_position.y - (machine.original_capsule_height / 2.0) var feet_y = player.global_position.y - (machine.original_capsule_height / 2.0)
# Raycast down from above the step # Raycast down from above the step using wall contact point
var fwd = wish_dir.normalized() var push_dir = -col.get_normal()
var ray_start = player.global_position + fwd * 0.65 push_dir.y = 0.0
if push_dir.length_squared() < 0.01:
push_dir = wish_dir.normalized()
else:
push_dir = push_dir.normalized()
var ray_start = col.get_position() + push_dir * 0.1
ray_start.y = feet_y + max_step_height + 0.1 ray_start.y = feet_y + max_step_height + 0.1
var ray_end = ray_start - Vector3.UP * (max_step_height + 0.2) var ray_end = ray_start - Vector3.UP * (max_step_height + 0.2)
@@ -125,13 +131,13 @@ func update(delta: float) -> void:
# Check if there is enough space to move forward after stepping up # Check if there is enough space to move forward after stepping up
var test_transform = player.global_transform var test_transform = player.global_transform
test_transform.origin.y += step_height + 0.05 test_transform.origin.y += step_height + 0.05
if not player.test_move(test_transform, fwd * 0.15): if not player.test_move(test_transform, push_dir * 0.15):
# We can safely step up # We can safely step up
player.global_position.y += step_height + 0.01 player.global_position.y += step_height + 0.01
if player.head_pivot and player.head_pivot.has_method("add_step_offset"): if player.head_pivot and player.head_pivot.has_method("add_step_offset"):
player.head_pivot.add_step_offset(-(step_height + 0.01)) player.head_pivot.add_step_offset(-(step_height + 0.01))
# Push slightly forward to get onto the step # Push slightly forward to get onto the step
player.global_position += fwd * 0.1 player.global_position += push_dir * 0.1
# Restore horizontal velocity that was lost from hitting the wall # Restore horizontal velocity that was lost from hitting the wall
player.velocity.x = hvel.x player.velocity.x = hvel.x
player.velocity.z = hvel.z player.velocity.z = hvel.z