buffered inputs revamped and added mantle jumps and dashed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user