feat: overhaul movement for flow — momentum-preserving states, smooth crouch, landing feel

- Quake-style air-strafe accelerate (real speed gain from strafing; external
  speed from dash/rockets never clamped)
- Wall run: keeps entry momentum (incl. upward carry), accelerates along the
  wall instead of hard-setting velocity, gravity fades in over the run
- Slide: slope physics (gravity projected along floor accelerates downhill),
  flat-ground decel instead of multiplicative friction, entry boost, direct
  slide->wallrun and slide->dash transitions
- Dash: cooldown 10s -> 2s, per-player (was a static shared across instances),
  momentum fully kept on exit, FOV punch event
- Grapple: taut pendulum with active rope control (W reels in, S pays out),
  release keeps swing energy
- Wall climb: carries upward momentum in, jump-off kick, shared vault helper
- Crouch capsule: single owner in the machine, smoothly lerped, ceiling check;
  camera eye height follows via crouch factor (no more head snapping)
- Landing: machine emits 'land' events scaled by impact; camera dip + pitched
  down thud; footsteps get pitch variation
- Camera rig: event-driven (land dip, dash FOV kick, vault pitch impulse),
  slide roll tilt
- Model: Jump vs Fall split by vertical velocity, Land one-shot on heavy
  landings, wall-run body lean (synced to remotes via synced_wall_side)

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Nicholas Butzke
2026-07-17 11:58:14 -04:00
co-authored by Claude Fable 5
parent c4a538a469
commit 0ba14a9469
16 changed files with 653 additions and 493 deletions
+43 -45
View File
@@ -1,25 +1,27 @@
extends Node
class_name StateWallRun
## Wall run that preserves momentum: on attach we keep speed along the wall
## (plus some upward carry) and accelerate toward wall_run_speed instead of
## hard-setting velocity, so entering fast stays fast and entering slow ramps
## up smoothly. Gravity fades in over the run so the start feels planted.
var machine: MovementStateMachine
var params: MovementParams:
get: return machine.params
var elapsed: float = 0.0
var _run_speed: float = 0.0
var _last_vel: Vector3 = Vector3.ZERO
var _current_tangent: Vector3 = Vector3.ZERO
func enter(_data: Dictionary = {}) -> void:
elapsed = 0.0
machine.register_chain_mechanic("wall_run")
# Cap the upward momentum so they don't fly up the wall,
# and prevent negative y momentum so the wall "catches" them.
machine.player.velocity.y = clampf(machine.player.velocity.y, 0.0, 1.5)
machine.on_ground = false
_last_vel = machine.player.velocity
# Keep some upward carry so jumping into a wall run flows; the wall
# still "catches" downward momentum.
machine.player.velocity.y = clampf(machine.player.velocity.y, 0.0, params.wall_run_entry_max_up)
if machine.player.wallrun_player and not machine.player.wallrun_player.playing:
machine.player.wallrun_player.play()
@@ -29,11 +31,6 @@ func enter(_data: Dictionary = {}) -> void:
if hvel.dot(_current_tangent) < 0.0:
_current_tangent = -_current_tangent
# Preserve speed along the wall if it's faster than base wall_run_speed
var base_speed = machine.get_effective_speed(params.wall_run_speed)
var projected_speed = hvel.dot(_current_tangent)
_run_speed = maxf(base_speed, projected_speed)
# Camera tilt
var rig = _get_camera_rig()
if rig:
@@ -45,7 +42,7 @@ func exit() -> void:
var rig = _get_camera_rig()
if rig:
rig.clear_wall_tilt()
if machine.player.wallrun_player:
machine.player.wallrun_player.stop()
@@ -53,61 +50,51 @@ func exit() -> void:
func update(delta: float) -> void:
elapsed += delta
if elapsed > params.wall_run_duration:
machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0
machine.wall_cooldown_timer = 0.3
machine.switch_to("air")
_detach(0.4)
return
var player := machine.player
var vel: Vector3 = player.velocity
if player.wallrun_player and not player.wallrun_player.playing:
player.wallrun_player.play()
if vel.distance_squared_to(_last_vel) > 100.0:
machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0
machine.switch_to("air")
return
# ── Gradual gravity pull (starts light, increases over time) ──────────
var gravity_factor := 0.1 + 0.9 * (elapsed / params.wall_run_duration)
# ── Gradual gravity pull (starts weightless, ramps up) ────────────────
var gravity_factor := 0.05 + 0.95 * pow(elapsed / params.wall_run_duration, 1.5)
vel.y -= params.wall_run_gravity * gravity_factor * delta
# ── Move along wall tangent ───────────────────────────────────────────
# ── Accelerate along wall tangent (keeps momentum, no hard set) ───────
var wall_tangent := machine.wall_normal.cross(Vector3.UP).normalized()
# Ensure the new tangent aligns with our locked forward direction
if _current_tangent.dot(wall_tangent) < 0.0:
wall_tangent = -wall_tangent
_current_tangent = wall_tangent
vel.x = wall_tangent.x * _run_speed
vel.z = wall_tangent.z * _run_speed
var hvel := Vector3(vel.x, 0.0, vel.z)
var along := hvel.dot(wall_tangent)
var target_speed: float = maxf(machine.get_effective_speed(params.wall_run_speed), along)
along = move_toward(along, target_speed, params.wall_run_accel * delta)
# Redirect all horizontal velocity along the wall (kills the into-wall part)
hvel = wall_tangent * along
vel.x = hvel.x
vel.z = hvel.z
# ── Look away to break wall run ───────────────────────────────────────
var look_dir := -player.global_transform.basis.z
if look_dir.dot(machine.wall_normal) > 0.4:
machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0
machine.wall_cooldown_timer = 0.3
machine.switch_to("air")
_detach(0.3)
return
# ── Push slightly toward wall to maintain contact ─────────────────────
vel -= machine.wall_normal * 2.0
# ── Wall jump ─────────────────────────────────────────────────────────
if machine.input_jump_just_pressed and machine.jump_cooldown_timer <= 0.0:
# Base jump off velocity on current preserved momentum
var jump_vel: Vector3 = _current_tangent * _run_speed
var jump_vel: Vector3 = _current_tangent * along
# Spring off the wall
jump_vel += machine.wall_normal * params.wall_run_jump_off_normal
var h_look := Vector3(look_dir.x, 0.0, look_dir.z)
if h_look.length_squared() > 0.01:
jump_vel += h_look.normalized() * params.wall_run_jump_horizontal
jump_vel.y = params.wall_run_auto_jump_speed
player.velocity = jump_vel
machine.wall_normal = Vector3.ZERO
@@ -115,6 +102,9 @@ func update(delta: float) -> void:
machine.wall_cooldown_timer = 0.3
machine.register_chain_mechanic("wall_jump")
machine.jump_cooldown_timer = params.jump_cooldown
machine.movement_event.emit("jump", {})
if player.jump_player:
player.jump_player.play()
machine.switch_to("air")
return
@@ -123,16 +113,16 @@ func update(delta: float) -> void:
machine.switch_to("wall_cling")
return
# ── Push slightly toward wall to maintain contact ─────────────────────
vel -= machine.wall_normal * 2.0
player.velocity = vel
player.move_and_slide()
_last_vel = player.velocity
# ── Check still on wall ───────────────────────────────────────────────
var still_on_wall := machine.detect_wall_horizontal()
if still_on_wall == Vector3.ZERO:
machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0
machine.switch_to("air")
_detach(0.0)
return
# ── Hit floor during wall run ─────────────────────────────────────────
@@ -144,6 +134,14 @@ func update(delta: float) -> void:
machine.switch_to("ground")
func _detach(cooldown: float) -> void:
machine.wall_normal = Vector3.ZERO
machine.wall_side = 0.0
if cooldown > 0.0:
machine.wall_cooldown_timer = cooldown
machine.switch_to("air")
func _get_camera_rig():
if machine.player and machine.player.has_node("HeadPivot"):
return machine.player.get_node("HeadPivot")