feat: implement dash and wall run movement states for the player controller

This commit is contained in:
DottsGit
2026-06-04 11:47:08 -04:00
parent 5c2d648801
commit d8cb91e593
2 changed files with 23 additions and 4 deletions
+14 -4
View File
@@ -8,6 +8,7 @@ var params: MovementParams:
var elapsed: float = 0.0 var elapsed: float = 0.0
var direction: Vector3 = Vector3.ZERO var direction: Vector3 = Vector3.ZERO
var _exit_speed: float = 0.0 var _exit_speed: float = 0.0
var _last_vel: Vector3 = Vector3.ZERO
# Cooldown tracked across dash instances # Cooldown tracked across dash instances
static var _last_dash_time: float = -999.0 static var _last_dash_time: float = -999.0
@@ -51,6 +52,7 @@ func enter(_data: Dictionary = {}) -> void:
machine.player.velocity = direction * _exit_speed machine.player.velocity = direction * _exit_speed
machine.on_ground = false machine.on_ground = false
_last_vel = machine.player.velocity
func exit() -> void: func exit() -> void:
@@ -70,9 +72,17 @@ func update(delta: float) -> void:
return return
# Maintain dash velocity # Maintain dash velocity
var vel = direction * _exit_speed var player := machine.player
if machine.player.is_on_floor(): var vel: Vector3 = player.velocity
if vel.distance_squared_to(_last_vel) > 100.0:
machine.switch_to("air")
return
vel = direction * _exit_speed
if player.is_on_floor():
vel.y = -0.5 # Snap to floor to handle ramps vel.y = -0.5 # Snap to floor to handle ramps
machine.player.velocity = vel player.velocity = vel
machine.player.move_and_slide() player.move_and_slide()
_last_vel = player.velocity
+9
View File
@@ -8,6 +8,7 @@ var params: MovementParams:
var elapsed: float = 0.0 var elapsed: float = 0.0
var _initial_y_vel: float = 0.0 var _initial_y_vel: float = 0.0
var _run_speed: float = 0.0 var _run_speed: float = 0.0
var _last_vel: Vector3 = Vector3.ZERO
var _current_tangent: Vector3 = Vector3.ZERO var _current_tangent: Vector3 = Vector3.ZERO
@@ -19,6 +20,7 @@ func enter(_data: Dictionary = {}) -> void:
# but preserve some if they just jumped onto it. # but preserve some if they just jumped onto it.
machine.player.velocity.y = minf(machine.player.velocity.y, 1.5) machine.player.velocity.y = minf(machine.player.velocity.y, 1.5)
machine.on_ground = false machine.on_ground = false
_last_vel = machine.player.velocity
var hvel := Vector3(machine.player.velocity.x, 0.0, machine.player.velocity.z) var hvel := Vector3(machine.player.velocity.x, 0.0, machine.player.velocity.z)
_current_tangent = machine.wall_normal.cross(Vector3.UP).normalized() _current_tangent = machine.wall_normal.cross(Vector3.UP).normalized()
@@ -54,6 +56,12 @@ func update(delta: float) -> void:
var player := machine.player var player := machine.player
var vel: Vector3 = player.velocity var vel: Vector3 = player.velocity
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) ────────── # ── Gradual gravity pull (starts light, increases over time) ──────────
var gravity_factor := 0.1 + 0.9 * (elapsed / params.wall_run_duration) var gravity_factor := 0.1 + 0.9 * (elapsed / params.wall_run_duration)
@@ -108,6 +116,7 @@ func update(delta: float) -> void:
player.velocity = vel player.velocity = vel
player.move_and_slide() player.move_and_slide()
_last_vel = player.velocity
# ── Check still on wall ─────────────────────────────────────────────── # ── Check still on wall ───────────────────────────────────────────────
var still_on_wall := machine.detect_wall_horizontal() var still_on_wall := machine.detect_wall_horizontal()