From ef16d6c83fecf0706e79c1491b0e35043169b043 Mon Sep 17 00:00:00 2001 From: Minimata Date: Sun, 6 Jul 2025 11:49:59 +0200 Subject: [PATCH] feat: broken crouching --- player_controller/PlayerController.tscn | 12 ++++----- player_controller/Scripts/PlayerController.cs | 26 +++++++++++++++++++ systems/head/HeadSystem.cs | 5 ++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 55eb206..c9388cf 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -320,29 +320,29 @@ delay_in_seconds = "0.0" [node name="OnCrouch" type="Node" parent="StateChart/Root/Movement/Grounded/Standing"] script = ExtResource("28_n7qhm") -to = NodePath("../../Crouch") +to = NodePath("../../Crouched") event = &"crouch" delay_in_seconds = "0.0" -[node name="Crouch" type="Node" parent="StateChart/Root/Movement/Grounded"] +[node name="Crouched" type="Node" parent="StateChart/Root/Movement/Grounded"] script = ExtResource("27_34snm") -[node name="OnJump" type="Node" parent="StateChart/Root/Movement/Grounded/Crouch"] +[node name="OnJump" type="Node" parent="StateChart/Root/Movement/Grounded/Crouched"] script = ExtResource("28_n7qhm") to = NodePath("../../../Airborne/Jump") event = &"jump" delay_in_seconds = "0.0" -[node name="OnAirborne" type="Node" parent="StateChart/Root/Movement/Grounded/Crouch"] +[node name="OnAirborne" type="Node" parent="StateChart/Root/Movement/Grounded/Crouched"] script = ExtResource("28_n7qhm") to = NodePath("../../../Airborne/CoyoteEnabled") event = &"start_falling" delay_in_seconds = "0.0" -[node name="OnStandUp" type="Node" parent="StateChart/Root/Movement/Grounded/Crouch"] +[node name="OnStandUp" type="Node" parent="StateChart/Root/Movement/Grounded/Crouched"] script = ExtResource("28_n7qhm") to = NodePath("../../Standing") -event = &"stand_up" +event = &"crouch" delay_in_seconds = "0.0" [node name="Mantling" type="Node" parent="StateChart/Root/Movement"] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 8fd237f..bc11f65 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -66,6 +66,8 @@ public partial class PlayerController : CharacterBody3D private StateChartState _actionHanging; // Movement state private StateChartState _grounded; + private StateChartState _crouched; + private StateChartState _standing; private StateChartState _mantling; private StateChartState _movHanging; private StateChartState _wallHugging; @@ -132,6 +134,8 @@ public partial class PlayerController : CharacterBody3D _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging")); // Movement states _grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded")); + _standing = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded/Standing")); + _crouched = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded/Crouched")); _mantling = StateChartState.Of(GetNode("StateChart/Root/Movement/Mantling")); _movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/Hanging")); _airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne")); @@ -200,6 +204,8 @@ public partial class PlayerController : CharacterBody3D _aiming.StateEntered += OnAimingEntered; _aiming.StateExited += ResetTimeScale; + _crouched.StatePhysicsProcessing += HandleGroundedCrouched; + _standing.StatePhysicsProcessing += HandleGroundedStanding; _grounded.StateEntered += OnGrounded; _grounded.StatePhysicsProcessing += HandleGrounded; _airborne.StatePhysicsProcessing += HandleAirborne; @@ -280,6 +286,16 @@ public partial class PlayerController : CharacterBody3D _isWallJumpAvailable = true; } + public void OnStanding() + { + + } + + public void OnCrouched() + { + + } + public bool CanPerformDashAction() { return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped(); @@ -495,6 +511,16 @@ public partial class PlayerController : CharacterBody3D if (!isOnFloorCustom()) _playerState.SendEvent("start_falling"); } + public void HandleGroundedStanding(float delta) + { + CapsuleCollider.UndoCrouching(delta, 1); + HeadSystem.SetHeight(CapsuleCollider.GetCurrentHeight()); + } + public void HandleGroundedCrouched(float delta) + { + CapsuleCollider.Crouch(delta, 1); + HeadSystem.SetHeight(CapsuleCollider.GetCurrentHeight()); + } public void HandleAirborne(float delta) { if (isOnFloorCustom()) diff --git a/systems/head/HeadSystem.cs b/systems/head/HeadSystem.cs index a0f199d..e81e3af 100644 --- a/systems/head/HeadSystem.cs +++ b/systems/head/HeadSystem.cs @@ -34,4 +34,9 @@ public partial class HeadSystem : Node3D { return GetGlobalTransform().Basis.Z; } + + public void SetHeight(float height) + { + Position = new Vector3(Position.X, height, Position.Z); + } } \ No newline at end of file