dash and jump
This commit is contained in:
@ -58,6 +58,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
public int DashIndicatorStartSize { get; set; } = 100;
|
||||
[Export(PropertyHint.Range, "0,1,0.01")]
|
||||
public float DashProgressAfterWhichToAct { get; set; } = 0.8f;
|
||||
[Export(PropertyHint.Range, "0,50,0.1")]
|
||||
public float BasicDashStrength { get; set; } = 10f;
|
||||
|
||||
[Export]
|
||||
public Curve DashTimeDilationCurve { get; set; }
|
||||
@ -76,25 +78,26 @@ public partial class PlayerController : CharacterBody3D
|
||||
private bool _isWallJumpAvailable = true;
|
||||
|
||||
private StateChart _playerState;
|
||||
// Actions state
|
||||
|
||||
private StateChartState _weaponInHand;
|
||||
private StateChartState _aiming;
|
||||
private StateChartState _dashing;
|
||||
private StateChartState _weaponThrown;
|
||||
private StateChartState _actionHanging;
|
||||
// Movement state
|
||||
private StateChartState _empowerOn;
|
||||
private StateChartState _empowerOff;
|
||||
|
||||
private StateChartState _grounded;
|
||||
private StateChartState _crouched;
|
||||
private StateChartState _standing;
|
||||
private StateChartState _mantling;
|
||||
private StateChartState _movHanging;
|
||||
private StateChartState _wallHugging;
|
||||
private StateChartState _airborne;
|
||||
private StateChartState _coyoteEnabled;
|
||||
private StateChartState _jump;
|
||||
private StateChartState _jumpFromWall;
|
||||
private StateChartState _doubleJumpEnabled;
|
||||
private StateChartState _doubleJump;
|
||||
private StateChartState _onWall;
|
||||
private StateChartState _onWallHugging;
|
||||
private StateChartState _onWallHanging;
|
||||
private StateChartState _falling;
|
||||
|
||||
public override void _Ready()
|
||||
@ -147,25 +150,26 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// State management
|
||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||
// 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
|
||||
|
||||
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponState/InHand"));
|
||||
_weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponState/Flying"));
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aim/On"));
|
||||
_dashing = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing"));
|
||||
// _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging"));
|
||||
_empowerOn = StateChartState.Of(GetNode("StateChart/Root/Empower/On"));
|
||||
_empowerOff = StateChartState.Of(GetNode("StateChart/Root/Empower/Off"));
|
||||
|
||||
_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"));
|
||||
_movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hanging"));
|
||||
_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"));
|
||||
_onWall = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall"));
|
||||
_onWallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hugging"));
|
||||
_onWallHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hanging"));
|
||||
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
|
||||
// State timers
|
||||
_coyoteTimer = GetNode<Timer>("CoyoteTime");
|
||||
@ -231,17 +235,13 @@ public partial class PlayerController : CharacterBody3D
|
||||
_grounded.StateEntered += OnGrounded;
|
||||
_grounded.StatePhysicsProcessing += HandleGrounded;
|
||||
_airborne.StatePhysicsProcessing += HandleAirborne;
|
||||
_wallHugging.StatePhysicsProcessing += HandleWallHugging;
|
||||
_onWallHugging.StatePhysicsProcessing += HandleWallHugging;
|
||||
|
||||
_coyoteEnabled.StateEntered += StartCoyoteTime;
|
||||
_coyoteTimer.Timeout += CoyoteExpired;
|
||||
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
|
||||
_jump.StateEntered += Jump;
|
||||
_jumpFromWall.StateEntered += JumpFromWall;
|
||||
_doubleJump.StateEntered += DoubleJump;
|
||||
_mantling.StateEntered += Mantle;
|
||||
|
||||
_dashing.StateEntered += OnDashStarted;
|
||||
_dashing.StatePhysicsProcessing += Dashing;
|
||||
_weaponThrown.StateEntered += OnWeaponThrown;
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
_playerState.SendEvent("cancel");
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
public void OnInputHitPressed()
|
||||
@ -286,16 +286,56 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
if (MoveSystem.CanMantle())
|
||||
{
|
||||
_playerState.SendEvent("mantle");
|
||||
Mantle();
|
||||
return;
|
||||
}
|
||||
if (_grounded.Active || _coyoteEnabled.Active)
|
||||
if (_empowerOn.Active)
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
else
|
||||
Jump();
|
||||
else if (_doubleJumpEnabled.Active)
|
||||
if (_empowerOn.Active)
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
else
|
||||
DoubleJump();
|
||||
else if (_onWall.Active)
|
||||
JumpFromWall(_empowerOn.Active);
|
||||
|
||||
_playerState.SendEvent("jump");
|
||||
|
||||
}
|
||||
public void OnInputDropPressed()
|
||||
public void OnInputDashPressed()
|
||||
{
|
||||
_playerState.SendEvent("crouch");
|
||||
_playerState.SendEvent("dash");
|
||||
PerformDash(_empowerOn.Active);
|
||||
}
|
||||
public void OnInputThrowPressed()
|
||||
{
|
||||
_playerState.SendEvent("throw");
|
||||
}
|
||||
public void OnInputEmpowerDown()
|
||||
{
|
||||
_playerState.SendEvent("empower_down");
|
||||
}
|
||||
public void OnInputEmpowerReleased()
|
||||
{
|
||||
_playerState.SendEvent("empower_released");
|
||||
}
|
||||
|
||||
public void PerformDash(bool isEmpowered)
|
||||
{
|
||||
var direction = HeadSystem.Transform.Basis * _inputMove;
|
||||
var planarDirection = new Vector3(direction.X, 0, direction.Z).Normalized();
|
||||
var dashStrength = isEmpowered ? BasicDashStrength * 2.5f : BasicDashStrength;
|
||||
SetVelocity(planarDirection * dashStrength);
|
||||
}
|
||||
|
||||
public void Dashing(float delta)
|
||||
{
|
||||
_playerState.SendEvent("dash_ended");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// Stateful logic /////////
|
||||
@ -308,12 +348,12 @@ public partial class PlayerController : CharacterBody3D
|
||||
_isWallJumpAvailable = true;
|
||||
}
|
||||
|
||||
public bool CanPerformDashAction()
|
||||
public bool CanPerformEmpoweredAction()
|
||||
{
|
||||
return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped();
|
||||
}
|
||||
|
||||
public void PerformDashAction()
|
||||
public void PerformEmpoweredAction()
|
||||
{
|
||||
_isWallJumpAvailable = true;
|
||||
_dashCooldownTimer.Start();
|
||||
@ -331,41 +371,37 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void Jump()
|
||||
{
|
||||
if (_aiming.Active && CanPerformDashAction())
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
_playerState.SendEvent("jump_from_dash");
|
||||
PerformDashAction();
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
return;
|
||||
}
|
||||
_playerState.SendEvent("to_double_jump");
|
||||
PerformJump(MoveSystem.JumpTypes.SimpleJump);
|
||||
}
|
||||
public void JumpFromWall()
|
||||
public void JumpFromWall(bool isEmpowered)
|
||||
{
|
||||
if (!_isWallJumpAvailable)
|
||||
return;
|
||||
|
||||
_isWallJumpAvailable = false;
|
||||
var wallNormal = WallHugSystem.GetWallNormal().UnwrapOr(Vector3.Up);
|
||||
var isLookingTowardsWall = HeadSystem.GetForwardHorizontalVector().Dot(wallNormal) > 0.7;
|
||||
var isLookingTowardsWall = HeadSystem.GetForwardHorizontalVector().Dot(wallNormal) > 0.5;
|
||||
var jumpDirection = isLookingTowardsWall ? Vector3.Up : wallNormal;
|
||||
if (_aiming.Active && CanPerformDashAction())
|
||||
if (isEmpowered && CanPerformEmpoweredAction())
|
||||
{
|
||||
_playerState.SendEvent("jump_from_dash");
|
||||
PerformDashAction();
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash, jumpDirection);
|
||||
return;
|
||||
}
|
||||
_playerState.SendEvent("jump_from_wall");
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromWall, jumpDirection);
|
||||
}
|
||||
public void DoubleJump()
|
||||
{
|
||||
_playerState.SendEvent("to_falling");
|
||||
if (_aiming.Active && CanPerformDashAction())
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformDashAction();
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
return;
|
||||
}
|
||||
@ -392,19 +428,20 @@ public partial class PlayerController : CharacterBody3D
|
||||
// Mantling
|
||||
public void Mantle()
|
||||
{
|
||||
_playerState.SendEvent("mantle");
|
||||
var optionTween = MoveSystem.Mantle();
|
||||
if (optionTween.IsSome(out var tween))
|
||||
tween.Finished += MantleFinished;
|
||||
}
|
||||
public void MantleFinished()
|
||||
{
|
||||
_playerState.SendEvent("to_grounded");
|
||||
_playerState.SendEvent("grounded");
|
||||
}
|
||||
|
||||
// Dashing and weapon throwing
|
||||
public void OnDashStarted()
|
||||
{
|
||||
if (!CanPerformDashAction())
|
||||
if (!CanPerformEmpoweredAction())
|
||||
{
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
_playerState.SendEvent("dash_ended");
|
||||
@ -412,7 +449,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
return;
|
||||
}
|
||||
|
||||
PerformDashAction();
|
||||
PerformEmpoweredAction();
|
||||
_timeAfterDashingTimer.Start();
|
||||
if (WeaponSystem.FlyingState.Active)
|
||||
{
|
||||
@ -503,7 +540,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnAimingEntered()
|
||||
{
|
||||
if (!isOnFloorCustom() && CanPerformDashAction())
|
||||
if (!isOnFloorCustom() && CanPerformEmpoweredAction())
|
||||
ReduceTimeScaleWhileAiming();
|
||||
}
|
||||
|
||||
@ -517,7 +554,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
RotateWeaponWithPlayer();
|
||||
if (isOnFloorCustom())
|
||||
ResetTimeScale();
|
||||
if (CanPerformDashAction())
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.PrepareDash();
|
||||
else
|
||||
{
|
||||
@ -551,6 +588,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void HandleWallHugging(float delta)
|
||||
{
|
||||
if (isOnFloorCustom())
|
||||
_playerState.SendEvent("grounded");
|
||||
if (!WallHugSystem.IsWallHugging())
|
||||
_playerState.SendEvent("start_falling");
|
||||
}
|
||||
@ -572,8 +611,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
isOnFloorCustom(),
|
||||
HealthSystem.IsDead(),
|
||||
IsHeadTouchingCeiling(),
|
||||
_actionHanging.Active,
|
||||
_wallHugging.Active);
|
||||
_onWallHanging.Active,
|
||||
_onWallHugging.Active);
|
||||
MoveSystem.MoveAround(moveAroundParams);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user