From 66be7838bb22958577f0d62068016b177e091b7c Mon Sep 17 00:00:00 2001 From: Minimata Date: Sun, 11 Jan 2026 18:14:53 +0100 Subject: [PATCH] buffered inputs revamped and added mantle jumps and dashed --- player_controller/PlayerController.tscn | 2 + player_controller/Scripts/PlayerController.cs | 66 +++++++++++++++---- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index ee2fe725..88ea88e1 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -67,6 +67,8 @@ AccelerationAir = 0.8 DecelerationAir = 0.02 Weight = 4.0 MantlePath = ExtResource("2_6lejt") +MantleDashStrength = 20.0 +MantleJumpStartVelocity = 13.0 CoyoteTime = 0.3 InputBufferFrames = 5 SimpleJumpStartVelocity = 6.0 diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index a83d2181..f16e686c 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -16,6 +16,16 @@ public partial class PlayerController : CharacterBody3D } private bool _isUsingGamepad; + public enum BufferedActions + { + None, + Jump, + MantleJump, + Dash, + MantleDash + } + private BufferedActions _bufferedAction = BufferedActions.None; + // User API to important child nodes. public HeadSystem HeadSystem; public Bobbing Bobbing; @@ -79,12 +89,19 @@ public partial class PlayerController : CharacterBody3D public float DecelerationAir = 1.0f; [Export(PropertyHint.Range, "0,10,0.01,or_greater")] public float Weight { get; set; } = 3.0f; + + // Mantle [ExportGroup("Mantle")] [Export(PropertyHint.Range, "0,1,0.01,or_greater")] public float MantleTime { get; set; } = 0.1f; [Export] public PackedScene MantlePath { get; set; } + [Export(PropertyHint.Range, "0,50,0.1")] + public float MantleDashStrength { get; set; } = 15f; + [Export(PropertyHint.Range, "0,100,1,or_greater")] + public float MantleJumpStartVelocity { get; set; } = 20.0f; + // Jump [ExportGroup("Jump")] [Export(PropertyHint.Range, "0,1,0.01")] @@ -207,7 +224,6 @@ public partial class PlayerController : CharacterBody3D private StateChartState _grounded; private StateChartState _airborne; private StateChartState _coyoteEnabled; - // private StateChartState _doubleJumpEnabled; private StateChartState _simpleJump; private StateChartState _doubleJump; private StateChartState _megaJump; @@ -231,7 +247,7 @@ public partial class PlayerController : CharacterBody3D private Transition _onLeaveWallFromRunCoyote; private Transition _onLeaveWallFromRun; - private int _currentJumpBufferFrames = 0; + private int _currentInputBufferFrames; private float _playerHeight; private float _playerRadius; @@ -470,12 +486,29 @@ public partial class PlayerController : CharacterBody3D if (_simpleDashCooldownTimer.IsStopped()) _simpleDashCooldownTimer.Start(); - - if (_currentJumpBufferFrames > 0) + + if (_bufferedAction == BufferedActions.Jump && _currentInputBufferFrames > 0) { - _currentJumpBufferFrames = 0; + _currentInputBufferFrames = 0; PerformJump(); } + if (_bufferedAction == BufferedActions.Dash && _currentInputBufferFrames > 0) + { + _currentInputBufferFrames = 0; + SimpleDash(); + } + + if (_bufferedAction == BufferedActions.MantleJump) + { + SimpleDash(); + OnJumpStarted(MantleJumpStartVelocity); + } + if (_bufferedAction == BufferedActions.MantleDash) + { + SimpleDash(MantleDashStrength); + } + + _bufferedAction = BufferedActions.None; } public void DashCooldownTimeout() @@ -649,8 +682,10 @@ public partial class PlayerController : CharacterBody3D // Jump public void OnInputJumpStarted() { - _currentJumpBufferFrames = InputBufferFrames; + _currentInputBufferFrames = InputBufferFrames; + _bufferedAction = _mantling.Active ? BufferedActions.MantleJump : BufferedActions.Jump; _isJumpInputPressed = true; + PerformJump(); } @@ -804,8 +839,8 @@ public partial class PlayerController : CharacterBody3D private Vector3 _velocityOnMantleStarted = Vector3.Zero; - private bool _mantleEndedOnOtherSideOfWall = false; - private bool _mantleFoundGround = false; + private bool _mantleEndedOnOtherSideOfWall; + private bool _mantleFoundGround; public void OnMantleStarted() { HeadSystem.OnMantle(); @@ -840,14 +875,15 @@ public partial class PlayerController : CharacterBody3D GlobalPosition = _mantlePath.Target.GlobalPosition; } - public void SimpleDashInDirection(Vector3 direction) + public void SimpleDashInDirection(Vector3 direction, float strength = -1) { - SetVelocity(direction * SimpleDashStrength); + if (strength < 0) strength = SimpleDashStrength; + SetVelocity(direction * strength); } - public void SimpleDash() + public void SimpleDash(float strength = -1) { - SimpleDashInDirection(GetInputGlobalHDirection()); + SimpleDashInDirection(GetInputGlobalHDirection(), strength); } public void MantleFinished() @@ -1014,7 +1050,9 @@ public partial class PlayerController : CharacterBody3D return; _canDashAirborne = false; } - + + _currentInputBufferFrames = InputBufferFrames; + _bufferedAction = _mantling.Active ? BufferedActions.MantleDash : BufferedActions.Dash; _playerState.SendEvent("dash"); } public void OnAimingEntered() @@ -1427,7 +1465,7 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// public override void _PhysicsProcess(double delta) { - if (_currentJumpBufferFrames > 0) _currentJumpBufferFrames -= 1; + if (_currentInputBufferFrames > 0) _currentInputBufferFrames -= 1; LookAround(delta); CameraModifications((float) delta);