gd: added bonus jump height if jumping right after dash, and time scale on aiming in air
This commit is contained in:
@ -42,6 +42,12 @@ public partial class PlayerController : CharacterBody3D
|
||||
private bool _dashCanceled;
|
||||
|
||||
private Timer _coyoteTimer;
|
||||
private Timer _timeScaleAimInAirTimer;
|
||||
private Timer _timeAfterDashingTimer;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float TimeScaleAimInAir { get; set; } = 0.2f;
|
||||
[Export(PropertyHint.Range, "1,5,0.1,or_greater")]
|
||||
public float MaxJumpBoostAfterDashing { get; set; } = 2f;
|
||||
|
||||
private StateChart _playerState;
|
||||
// Actions state
|
||||
@ -130,6 +136,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
|
||||
// State timers
|
||||
_coyoteTimer = GetNode<Timer>("CoyoteTime");
|
||||
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
|
||||
_timeAfterDashingTimer = GetNode<Timer>("TimeAfterDashing");
|
||||
|
||||
///////////////////////////
|
||||
// Initialize components //
|
||||
@ -178,6 +186,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
_weaponInHand.StateProcessing += HandleWeaponInHand;
|
||||
_aiming.StateProcessing += HandleAiming;
|
||||
_aiming.StateEntered += OnAimingEntered;
|
||||
_aiming.StateExited += ResetTimeScale;
|
||||
|
||||
_grounded.StatePhysicsProcessing += HandleGrounded;
|
||||
_airborne.StatePhysicsProcessing += HandleAirborne;
|
||||
@ -185,6 +195,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
_coyoteEnabled.StateEntered += StartCoyoteTime;
|
||||
_coyoteTimer.Timeout += CoyoteExpired;
|
||||
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
|
||||
_jump.StateEntered += Jump;
|
||||
_jumpFromWall.StateEntered += JumpFromWall;
|
||||
_doubleJump.StateEntered += DoubleJump;
|
||||
@ -277,10 +288,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
|
||||
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
|
||||
|
||||
var actualBoost = 1 + MaxJumpBoostAfterDashing * _timeAfterDashingTimer.TimeLeft;
|
||||
_timeAfterDashingTimer.Stop();
|
||||
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(isDoubleJump, jumpVector);
|
||||
MoveSystem.Jump(isDoubleJump, jumpVector, (float) actualBoost);
|
||||
}
|
||||
|
||||
// Mantling
|
||||
@ -298,6 +313,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
// Dashing and weapon throwing
|
||||
public void OnDashStarted()
|
||||
{
|
||||
_timeAfterDashingTimer.Start();
|
||||
if (WeaponSystem.FlyingState.Active)
|
||||
{
|
||||
DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero);
|
||||
@ -359,6 +375,11 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashSystem.CancelDash();
|
||||
WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal);
|
||||
}
|
||||
public void OnAimingEntered()
|
||||
{
|
||||
if (!isOnFloorCustom())
|
||||
ReduceTimeScaleWhileAiming();
|
||||
}
|
||||
|
||||
// Regular processes
|
||||
public void HandleWeaponInHand(float delta)
|
||||
@ -369,6 +390,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
RotateWeaponWithPlayer();
|
||||
DashSystem.PrepareDash();
|
||||
|
||||
if (isOnFloorCustom())
|
||||
ResetTimeScale();
|
||||
}
|
||||
|
||||
// Physics processes
|
||||
@ -384,7 +408,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
if (WallHugSystem.IsWallHugging() && Velocity.Y < 0)
|
||||
_playerState.SendEvent("wall_hug");
|
||||
}
|
||||
|
||||
public void HandleWallHugging(float delta)
|
||||
{
|
||||
if (!WallHugSystem.IsWallHugging())
|
||||
@ -494,6 +517,16 @@ public partial class PlayerController : CharacterBody3D
|
||||
///////////////////////////
|
||||
// Helpers ////////////////
|
||||
///////////////////////////
|
||||
public void ReduceTimeScaleWhileAiming()
|
||||
{
|
||||
Engine.SetTimeScale(TimeScaleAimInAir);
|
||||
_timeScaleAimInAirTimer.Start();
|
||||
}
|
||||
public void ResetTimeScale()
|
||||
{
|
||||
Engine.SetTimeScale(1);
|
||||
}
|
||||
|
||||
private bool IsHeadTouchingCeiling()
|
||||
{
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
|
Reference in New Issue
Block a user