gd: added wall hugging

This commit is contained in:
2025-06-10 11:46:51 +02:00
parent 141688ef32
commit 0c015750fd
5 changed files with 135 additions and 28 deletions

View File

@ -21,6 +21,7 @@ public partial class PlayerController : CharacterBody3D
public TweenQueueSystem TweenQueueSystem;
public Node3D WeaponRoot;
public WeaponSystem WeaponSystem;
public WallHugSystem WallHugSystem;
private bool _movementEnabled = true;
@ -57,6 +58,7 @@ public partial class PlayerController : CharacterBody3D
private StateChartState _airborne;
private StateChartState _coyoteEnabled;
private StateChartState _jump;
private StateChartState _jumpFromWall;
private StateChartState _doubleJumpEnabled;
private StateChartState _doubleJump;
private StateChartState _falling;
@ -92,6 +94,7 @@ public partial class PlayerController : CharacterBody3D
MoveSystem = GetNode<MoveSystem>("MoveSystem");
DashSystem = GetNode<DashSystem>("DashSystem");
StairsSystem = GetNode<StairsSystem>("StairsSystem");
WallHugSystem = GetNode<WallHugSystem>("WallHugSystem");
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
@ -117,10 +120,11 @@ public partial class PlayerController : CharacterBody3D
_grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded"));
_mantling = StateChartState.Of(GetNode("StateChart/Root/Movement/Mantling"));
_movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/Hanging"));
_wallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/WallHugging"));
_airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne"));
_wallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/WallHugging"));
_coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled"));
_jump = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Jump"));
_jumpFromWall = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/JumpFromWall"));
_doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled"));
_doubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJump"));
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
@ -150,6 +154,7 @@ public partial class PlayerController : CharacterBody3D
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
DashSystem.Init(HeadSystem, camera, TweenQueueSystem);
WeaponSystem.Init(HeadSystem, camera);
WallHugSystem.Init();
// RPG Stuff
HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams()
@ -179,6 +184,7 @@ public partial class PlayerController : CharacterBody3D
_coyoteEnabled.StateEntered += StartCoyoteTime;
_coyoteTimer.Timeout += CoyoteExpired;
_jump.StateEntered += Jump;
_jumpFromWall.StateEntered += JumpFromWall;
_doubleJump.StateEntered += DoubleJump;
_mantling.StateEntered += Mantle;
@ -252,17 +258,27 @@ public partial class PlayerController : CharacterBody3D
_playerState.SendEvent("to_double_jump");
PerformJump(false);
}
public void JumpFromWall()
{
_playerState.SendEvent("to_double_jump");
var wallNormal = WallHugSystem.GetWallNormal();
if (wallNormal.IsSome(out var normal))
PerformJump(false, normal);
PerformJump(false);
}
public void DoubleJump()
{
_playerState.SendEvent("to_falling");
PerformJump(true);
}
private void PerformJump(bool isDoubleJump)
private void PerformJump(bool isDoubleJump, Vector3? jumpDirection = null)
{
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
bool isPlayerDead = HealthSystem.IsDead();
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
MoveSystem.Jump(isDoubleJump);
MoveSystem.Jump(isDoubleJump, jumpVector);
}
// Mantling
@ -363,6 +379,8 @@ public partial class PlayerController : CharacterBody3D
{
if (isOnFloorCustom())
_playerState.SendEvent("grounded");
if (WallHugSystem.IsWallHugging() && Velocity.Y < 0)
_playerState.SendEvent("wall_hug");
}
///////////////////////////
@ -382,7 +400,8 @@ public partial class PlayerController : CharacterBody3D
isOnFloorCustom(),
HealthSystem.IsDead(),
IsHeadTouchingCeiling(),
_actionHanging.Active);
_actionHanging.Active,
_wallHugging.Active);
MoveSystem.MoveAround(moveAroundParams);
}
@ -502,4 +521,5 @@ public partial class PlayerController : CharacterBody3D
CameraModifications((float) delta);
HandleStairs((float) delta);
}
}