trying other setup
This commit is contained in:
@ -46,6 +46,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private Timer _timeScaleAimInAirTimer;
|
||||
private Timer _timeAfterDashingTimer;
|
||||
private Timer _dashCooldownTimer;
|
||||
private Timer _empowerTimeDownscale;
|
||||
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float TimeScaleAimInAir { get; set; } = 0.2f;
|
||||
@ -57,25 +58,27 @@ public partial class PlayerController : CharacterBody3D
|
||||
[Export(PropertyHint.Range, "0,200,1,or_greater")]
|
||||
public int DashIndicatorStartSize { get; set; } = 100;
|
||||
[Export(PropertyHint.Range, "0,1,0.01")]
|
||||
public float DashProgressAfterWhichToAct { get; set; } = 0.8f;
|
||||
public float PerfectlyTimedActionTimer { get; set; } = 0.8f;
|
||||
[Export(PropertyHint.Range, "0,50,0.1")]
|
||||
public float BasicDashStrength { get; set; } = 10f;
|
||||
|
||||
[Export]
|
||||
public Curve DashTimeDilationCurve { get; set; }
|
||||
private bool _canDash = true;
|
||||
|
||||
private int _dashActionsLeft;
|
||||
public int DashActionsLeft
|
||||
private int _empoweredActionsLeft;
|
||||
public int EmpoweredActionsLeft
|
||||
{
|
||||
get => _dashActionsLeft;
|
||||
get => _empoweredActionsLeft;
|
||||
set
|
||||
{
|
||||
_dashActionsLeft = value;
|
||||
_empoweredActionsLeft = value;
|
||||
PlayerUi.SetNumberOfDashesLeft(value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isWallJumpAvailable = true;
|
||||
private bool _isActionPerfectlyTimed = false;
|
||||
|
||||
private StateChart _playerState;
|
||||
|
||||
@ -176,6 +179,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
_dashCooldownTimer = GetNode<Timer>("DashCooldown");
|
||||
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
|
||||
_timeAfterDashingTimer = GetNode<Timer>("TimeAfterDashing");
|
||||
_empowerTimeDownscale = GetNode<Timer>("EmpowerTimeDownscale");
|
||||
|
||||
///////////////////////////
|
||||
// Initialize components //
|
||||
@ -216,7 +220,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
|
||||
|
||||
DashActionsLeft = MaxNumberOfDashActions;
|
||||
EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
|
||||
///////////////////////////
|
||||
// Signal setup ///////////
|
||||
@ -229,9 +233,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
_aiming.StateProcessing += HandleAiming;
|
||||
_aiming.StateEntered += OnAimingEntered;
|
||||
_aiming.StateExited += ResetTimeScale;
|
||||
_aiming.StateExited += OnAimingExited;
|
||||
|
||||
/*_crouched.StatePhysicsProcessing += HandleGroundedCrouched;
|
||||
_standing.StatePhysicsProcessing += HandleGroundedStanding;*/
|
||||
_grounded.StateEntered += OnGrounded;
|
||||
_grounded.StatePhysicsProcessing += HandleGrounded;
|
||||
_airborne.StatePhysicsProcessing += HandleAirborne;
|
||||
@ -242,7 +245,36 @@ public partial class PlayerController : CharacterBody3D
|
||||
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
|
||||
|
||||
_dashing.StatePhysicsProcessing += Dashing;
|
||||
_weaponThrown.StateEntered += OnWeaponThrown;
|
||||
// _weaponThrown.StateEntered += OnWeaponThrown;
|
||||
|
||||
_empowerOn.StateEntered += OnEmpowerStarted;
|
||||
_empowerOn.StateProcessing += HandleEmpower;
|
||||
_empowerTimeDownscale.Timeout += EmpowerStopped;
|
||||
}
|
||||
|
||||
public void OnEmpowerStarted()
|
||||
{
|
||||
_empowerTimeDownscale.Start();
|
||||
_isActionPerfectlyTimed = true;
|
||||
Engine.SetTimeScale(0.1f);
|
||||
}
|
||||
|
||||
public void HandleEmpower(float delta)
|
||||
{
|
||||
var progress = (float) (_empowerTimeDownscale.TimeLeft / _empowerTimeDownscale.WaitTime);
|
||||
_isActionPerfectlyTimed = progress < PerfectlyTimedActionTimer;
|
||||
var indicatorColor = _isActionPerfectlyTimed ? Colors.Green : Colors.White;
|
||||
|
||||
DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * progress);
|
||||
DashIndicator.SetModulate(indicatorColor);
|
||||
DashIndicator.Visible = true;
|
||||
}
|
||||
|
||||
public void EmpowerStopped()
|
||||
{
|
||||
DashIndicator.Visible = false;
|
||||
ResetTimeScale();
|
||||
_isActionPerfectlyTimed = false;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
@ -264,6 +296,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
_playerState.SendEvent("aim_pressed");
|
||||
if (!WeaponSystem.InHandState.Active)
|
||||
{
|
||||
OnDashStarted();
|
||||
}
|
||||
}
|
||||
public void OnInputAimDown()
|
||||
{
|
||||
@ -280,7 +316,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
_playerState.SendEvent("hit_pressed");
|
||||
if (_aiming.Active)
|
||||
{
|
||||
OnWeaponThrown();
|
||||
}
|
||||
}
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
@ -290,15 +329,21 @@ public partial class PlayerController : CharacterBody3D
|
||||
return;
|
||||
}
|
||||
if (_grounded.Active || _coyoteEnabled.Active)
|
||||
if (_empowerOn.Active)
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
}
|
||||
else
|
||||
Jump();
|
||||
PerformJump(MoveSystem.JumpTypes.SimpleJump);
|
||||
else if (_doubleJumpEnabled.Active)
|
||||
if (_empowerOn.Active)
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
}
|
||||
else
|
||||
DoubleJump();
|
||||
PerformJump(MoveSystem.JumpTypes.DoubleJump);
|
||||
else if (_onWall.Active)
|
||||
JumpFromWall(_empowerOn.Active);
|
||||
|
||||
@ -312,7 +357,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnInputThrowPressed()
|
||||
{
|
||||
_playerState.SendEvent("throw");
|
||||
|
||||
}
|
||||
public void OnInputEmpowerDown()
|
||||
{
|
||||
@ -325,9 +370,25 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void PerformDash(bool isEmpowered)
|
||||
{
|
||||
if (_aiming.Active)
|
||||
{
|
||||
OnDashStarted();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_canDash)
|
||||
return;
|
||||
|
||||
_canDash = false;
|
||||
var dashStrength = BasicDashStrength;
|
||||
if (isEmpowered && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
dashStrength *= 2.5f;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -344,20 +405,31 @@ public partial class PlayerController : CharacterBody3D
|
||||
// Simple states
|
||||
public void OnGrounded()
|
||||
{
|
||||
DashActionsLeft = MaxNumberOfDashActions;
|
||||
RestoreEmpoweredActions();
|
||||
}
|
||||
|
||||
private void RestoreEmpoweredActions()
|
||||
{
|
||||
EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
_isWallJumpAvailable = true;
|
||||
}
|
||||
|
||||
public bool CanPerformEmpoweredAction()
|
||||
{
|
||||
return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped();
|
||||
return EmpoweredActionsLeft > 0;
|
||||
}
|
||||
|
||||
public void PerformEmpoweredAction()
|
||||
{
|
||||
_isWallJumpAvailable = true;
|
||||
_dashCooldownTimer.Start();
|
||||
DashActionsLeft--;
|
||||
|
||||
if (!_isActionPerfectlyTimed)
|
||||
{
|
||||
EmpoweredActionsLeft--;
|
||||
}
|
||||
_empowerTimeDownscale.Stop();
|
||||
EmpowerStopped();
|
||||
}
|
||||
|
||||
// Jumping
|
||||
@ -369,17 +441,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_playerState.SendEvent("coyote_expired");
|
||||
}
|
||||
public void Jump()
|
||||
{
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
_playerState.SendEvent("jump_from_dash");
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
return;
|
||||
}
|
||||
PerformJump(MoveSystem.JumpTypes.SimpleJump);
|
||||
}
|
||||
public void JumpFromWall(bool isEmpowered)
|
||||
{
|
||||
if (!_isWallJumpAvailable)
|
||||
@ -397,16 +458,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromWall, jumpDirection);
|
||||
}
|
||||
public void DoubleJump()
|
||||
{
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
|
||||
return;
|
||||
}
|
||||
PerformJump(MoveSystem.JumpTypes.DoubleJump);
|
||||
}
|
||||
private void PerformJump(MoveSystem.JumpTypes jumpType, Vector3? jumpDirection = null)
|
||||
{
|
||||
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
|
||||
@ -478,10 +529,12 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void OnDashProgress(float progress)
|
||||
{
|
||||
return;
|
||||
|
||||
Engine.SetTimeScale(DashTimeDilationCurve.Sample(progress));
|
||||
|
||||
DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * (1 - progress));
|
||||
var indicatorColor = progress < DashProgressAfterWhichToAct ? new Color(1, 1, 1) : new Color(0, 1, 0);
|
||||
var indicatorColor = progress < PerfectlyTimedActionTimer ? new Color(1, 1, 1) : new Color(0, 1, 0);
|
||||
DashIndicator.SetModulate(indicatorColor);
|
||||
}
|
||||
public void OnDashEnded()
|
||||
@ -522,15 +575,18 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// Weapon planted anywhere else
|
||||
_playerState.SendEvent("dash_ended");
|
||||
if (isOnFloorCustom())
|
||||
RestoreEmpoweredActions(); // Make sure to restore actions if we're still on the ground
|
||||
}
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
DashSystem.CancelDash();
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
|
||||
RemoveChild(WeaponRoot);
|
||||
GetTree().GetRoot().AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
|
||||
DashSystem.CancelDash();
|
||||
|
||||
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation;
|
||||
WeaponSystem.ThrowWeapon(
|
||||
weaponTargetLocation,
|
||||
@ -540,32 +596,38 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnAimingEntered()
|
||||
{
|
||||
if (!WeaponSystem.InHandState.Active)
|
||||
{
|
||||
OnDashStarted();
|
||||
return;
|
||||
}
|
||||
if (!isOnFloorCustom() && CanPerformEmpoweredAction())
|
||||
ReduceTimeScaleWhileAiming();
|
||||
}
|
||||
|
||||
public void OnAimingExited()
|
||||
{
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
// Regular processes
|
||||
public void HandleWeaponInHand(float delta)
|
||||
{
|
||||
RotateWeaponWithPlayer();
|
||||
if (WeaponSystem.InHandState.Active)
|
||||
RotateWeaponWithPlayer();
|
||||
}
|
||||
public void HandleAiming(float delta)
|
||||
{
|
||||
RotateWeaponWithPlayer();
|
||||
if (isOnFloorCustom())
|
||||
ResetTimeScale();
|
||||
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.PrepareDash();
|
||||
else
|
||||
{
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
}
|
||||
|
||||
// Physics processes
|
||||
public void HandleGrounded(float delta)
|
||||
{
|
||||
_canDash = true;
|
||||
if (!isOnFloorCustom())
|
||||
_playerState.SendEvent("start_falling");
|
||||
}
|
||||
|
Reference in New Issue
Block a user