diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 2f0ea89..5963319 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -137,6 +137,8 @@ transform = Transform3D(1, 0, 0, 0, 0.173648, -0.984808, 0, 0.984808, 0.173648, ThrowForce = 25.0 StraightThrowDuration = 0.07 +[node name="CoyoteTime" type="Timer" parent="."] + [node name="StateChart" type="Node" parent="."] script = ExtResource("25_wv70j") metadata/_custom_type_script = "uid://couw105c3bde4" diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 824aa1c..bdc8eae 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -41,11 +41,20 @@ public partial class PlayerController : CharacterBody3D private bool _dashCanceled; private StateChart _playerState; + // Actions state private StateChartState _weaponInHand; private StateChartState _aiming; private StateChartState _dashing; private StateChartState _weaponThrown; - private StateChartState _hanging; + private StateChartState _actionHanging; + // Movement state + private StateChartState _grounded; + private StateChartState _movHanging; + private StateChartState _wallHugging; + private StateChartState _airborne; + private StateChartState _coyoteEnabled; + private StateChartState _doubleJumpEnabled; + private StateChartState _falling; public override void _Ready() { @@ -93,11 +102,20 @@ public partial class PlayerController : CharacterBody3D // State management _playerState = StateChart.Of(GetNode("StateChart")); - _weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponInHand")); - _aiming = StateChartState.Of(GetNode("StateChart/Root/Aiming")); - _dashing = StateChartState.Of(GetNode("StateChart/Root/Dashing")); - _weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponThrown")); - _hanging = StateChartState.Of(GetNode("StateChart/Root/Hanging")); + // Actions states + _weaponInHand = StateChartState.Of(GetNode("StateChart/Root/Actions/WeaponInHand")); + _aiming = StateChartState.Of(GetNode("StateChart/Root/Actions/Aiming")); + _dashing = StateChartState.Of(GetNode("StateChart/Root/Actions/Dashing")); + _weaponThrown = StateChartState.Of(GetNode("StateChart/Root/Actions/WeaponThrown")); + _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging")); + // Movement states + _grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded")); + _movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/Hanging")); + _wallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/WallHugging")); + _airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne")); + _coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled")); + _doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled")); + _falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling")); /////////////////////////// // Initialize components // @@ -162,19 +180,6 @@ public partial class PlayerController : CharacterBody3D _dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized(); DashSystem.Dash(); } - - public void OnWeaponThrown() - { - RemoveChild(WeaponRoot); - GetTree().GetRoot().AddChild(WeaponRoot); - WeaponRoot.SetGlobalPosition(GlobalPosition); - - var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation; - var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve; - - DashSystem.CancelDash(); - WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); - } public void OnDashEnded() { @@ -215,6 +220,19 @@ public partial class PlayerController : CharacterBody3D _playerState.SendEvent("dash_ended"); } + public void OnWeaponThrown() + { + RemoveChild(WeaponRoot); + GetTree().GetRoot().AddChild(WeaponRoot); + WeaponRoot.SetGlobalPosition(GlobalPosition); + + var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation; + var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve; + + DashSystem.CancelDash(); + WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); + } + public void OnInputMove(Vector3 value) { _inputMove = value; @@ -277,7 +295,7 @@ public partial class PlayerController : CharacterBody3D isOnFloorCustom(), isPlayerDead, isHeadTouchingCeiling, - _hanging.Active); + _actionHanging.Active); MoveSystem.MoveAround(moveAroundParams); Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);