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,45 @@
|
||||
extends Node
|
||||
class_name StateDash
|
||||
|
||||
var machine: MovementStateMachine
|
||||
var params: MovementParams:
|
||||
get: return machine.params
|
||||
|
||||
var elapsed: float = 0.0
|
||||
var direction: Vector3 = Vector3.ZERO
|
||||
var dash_cooldown_timer: float = 0.0
|
||||
|
||||
|
||||
func enter(_data: Dictionary = {}) -> void:
|
||||
elapsed = 0.0
|
||||
dash_cooldown_timer = params.dash_cooldown
|
||||
var input_v := machine.input_dir
|
||||
var wish_dir := Vector3(input_v.x, 0.0, -input_v.y)
|
||||
if wish_dir.length_squared() > 0.0:
|
||||
direction = wish_dir.normalized()
|
||||
else:
|
||||
direction = -machine.player.global_transform.basis.z.normalized()
|
||||
direction.y = 0.0
|
||||
direction = direction.normalized()
|
||||
direction = (machine.player.global_transform.basis * Vector4(direction.x, 0.0, direction.y, 0.0)).normalized()
|
||||
machine.register_chain_mechanic("dash")
|
||||
machine.player.velocity = direction * machine.get_effective_speed(params.dash_speed)
|
||||
machine.on_ground = false
|
||||
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func update(delta: float) -> void:
|
||||
elapsed += delta
|
||||
dash_cooldown_timer -= delta
|
||||
if elapsed > params.dash_duration:
|
||||
machine.switch_to("air")
|
||||
return
|
||||
# Skip gravity, maintain dash velocity
|
||||
machine.player.velocity = direction * machine.get_effective_speed(params.dash_speed)
|
||||
machine.player.move_and_slide()
|
||||
if machine.player.is_on_floor():
|
||||
machine.on_ground = true
|
||||
machine.switch_to("ground")
|
||||
Reference in New Issue
Block a user