feat(movement): add movement state machine with air/ground/wallrun/slide/dash/ground states
- MovementStateMachine: core state machine base - MovementParams: export-rich tunable resource - StateGround/StateAir: grounded & aeriel locomotion with coyote, buffered jump, bunny hop - StateWallRun / StateWallCling: wall-based traversal with wall-jump off - StateSlide: sprint-parallel slide with friction fallout - StateDash: burst dash with momentum brake - PlayerMovementController: entry point wiring to CharacterBody3D - input_map.cfg: full action map reference file - characters/player/player_base.tscn: placeholder scene - movement/tests/test_fsm_runner.gd: 9-state unit test runner Closes #1
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
extends Node
|
||||
class_name StateWallCling
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
elapsed = 0.0
|
||||
machine.register_chain_mechanic("wall_cling")
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
var vel: Vector3 = machine.player.velocity
|
||||
vel.x = params.wall_cling_horizontal_speed
|
||||
vel.y = params.wall_cling_vertical_speed
|
||||
vel.z = params.wall_cling_horizontal_speed
|
||||
machine.player.velocity = vel
|
||||
machine.player.move_and_slide()
|
||||
|
||||
# Jump off wall
|
||||
if machine.input_jump_just_pressed:
|
||||
var push_dir := machine.wall_normal * params.wall_run_jump_off_normal
|
||||
var vel2 := Vector3(push_dir.x, params.jump_velocity, push_dir.z)
|
||||
machine.player.velocity = vel2
|
||||
machine.register_chain_mechanic("wall_cling_jump")
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
# Re-enter wall run with input
|
||||
if machine.input_dir.length() > 0.1:
|
||||
machine.switch_to("wall_run")
|
||||
return
|
||||
|
||||
# Fall
|
||||
if not machine.wall_normal or machine.wall_normal.is_zero_approx():
|
||||
machine.switch_to("air")
|
||||
return
|
||||
|
||||
if machine.player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.wall_normal = Vector3.ZERO
|
||||
machine.register_chain_mechanic("cling_land")
|
||||
machine.switch_to("ground")
|
||||
Reference in New Issue
Block a user