least worst version
This commit is contained in:
@ -125,6 +125,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
public float PoweredDashTime { get; set; } = 0.3f;
|
||||
[Export(PropertyHint.Range, "0,100,0.1")]
|
||||
public float PoweredDashStrength { get; set; } = 10f;
|
||||
// Aimed Dash
|
||||
[ExportSubgroup("Aimed")]
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float AimedDashTime { get; set; } = 0.1f;
|
||||
|
||||
// Wall hug
|
||||
[ExportGroup("Wall hug")]
|
||||
@ -184,6 +188,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private StateChartState _megaJump;
|
||||
private StateChartState _simpleDash;
|
||||
private StateChartState _poweredDash;
|
||||
private StateChartState _aimedDash;
|
||||
private StateChartState _doubleJumpEnabled;
|
||||
private StateChartState _onWall;
|
||||
private StateChartState _onWallHugCanceled;
|
||||
@ -194,6 +199,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
private Transition _onJumpFromWall;
|
||||
private Transition _onMegajumpFromWall;
|
||||
|
||||
private float _playerHeight;
|
||||
private float _playerRadius;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
///////////////////////////
|
||||
@ -240,6 +248,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
"HeadCollisionDetectors/HeadCollisionDetector" + i);
|
||||
}
|
||||
|
||||
var playerShape = CapsuleCollider.GetShape() as CapsuleShape3D;
|
||||
_playerHeight = playerShape!.Height;
|
||||
_playerRadius = playerShape.Radius;
|
||||
|
||||
// RPG Stuff
|
||||
Stamina = GetNode<Stamina>("Stamina");
|
||||
HealthSystem = GetNode<HealthSystem>("HealthSystem");
|
||||
@ -252,6 +264,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aim/On"));
|
||||
_simpleDash = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing/Dash"));
|
||||
_poweredDash = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing/PoweredDash"));
|
||||
_aimedDash = StateChartState.Of(GetNode("StateChart/Root/Movement/Dashing/AimedDash"));
|
||||
// _actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging"));
|
||||
_empowerOn = StateChartState.Of(GetNode("StateChart/Root/Empower/On"));
|
||||
_empowerOff = StateChartState.Of(GetNode("StateChart/Root/Empower/Off"));
|
||||
@ -320,14 +333,13 @@ public partial class PlayerController : CharacterBody3D
|
||||
// Signal setup ///////////
|
||||
///////////////////////////
|
||||
_weaponInHand.StateProcessing += HandleWeaponInHand;
|
||||
_aiming.StateProcessing += HandleAiming;
|
||||
_aiming.StatePhysicsProcessing += HandleAiming;
|
||||
_aiming.StateEntered += OnAimingEntered;
|
||||
_aiming.StateExited += ResetTimeScale;
|
||||
_aiming.StateExited += OnAimingExited;
|
||||
|
||||
_grounded.StateEntered += OnGrounded;
|
||||
_grounded.StatePhysicsProcessing += HandleGrounded;
|
||||
_airborne.StateEntered += OnAirborne;
|
||||
_airborne.StatePhysicsProcessing += HandleAirborne;
|
||||
|
||||
_coyoteEnabled.StateEntered += StartCoyoteTime;
|
||||
@ -357,6 +369,10 @@ public partial class PlayerController : CharacterBody3D
|
||||
_poweredDash.StateEntered += OnPoweredDashStarted;
|
||||
_poweredDash.StatePhysicsProcessing += HandlePoweredDash;
|
||||
_poweredDash.StateExited += OnPoweredDashFinished;
|
||||
|
||||
_aimedDash.StateEntered += OnAimedDashStarted;
|
||||
_aimedDash.StatePhysicsProcessing += HandleAimedDash;
|
||||
_aimedDash.StateExited += OnAimedDashFinished;
|
||||
|
||||
_simpleDashCooldownTimer.Timeout += DashCooldownTimeout;
|
||||
|
||||
@ -384,9 +400,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
_simpleDashCooldownTimer.Start();
|
||||
}
|
||||
|
||||
public void OnAirborne()
|
||||
{
|
||||
}
|
||||
public void DashCooldownTimeout()
|
||||
{
|
||||
_canDash = true;
|
||||
@ -655,7 +668,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_playerState.SendEvent("cancel");
|
||||
DashSystem.CancelDash();
|
||||
DashSystem.StopPreparingDash();
|
||||
}
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
@ -672,11 +685,16 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_playerState.SendEvent("empower_released");
|
||||
}
|
||||
|
||||
private bool _dashAvailable = true;
|
||||
|
||||
public void OnInputDashPressed()
|
||||
{
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
_playerState.SendEvent("aimed_dash");
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
return;
|
||||
}
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
@ -693,6 +711,92 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
_playerState.SendEvent("dash");
|
||||
}
|
||||
|
||||
public void OnAimingEntered()
|
||||
{
|
||||
// if (!WeaponSystem.InHandState.Active)
|
||||
// {
|
||||
// OnDashStarted();
|
||||
// return;
|
||||
// }
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.StartPreparingDash();
|
||||
|
||||
if (!isOnFloorCustom() && CanPerformEmpoweredAction())
|
||||
ReduceTimeScaleWhileAiming();
|
||||
}
|
||||
public void HandleAiming(float delta)
|
||||
{
|
||||
RotateWeaponWithPlayer();
|
||||
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
public void OnAimingExited()
|
||||
{
|
||||
DashSystem.StopPreparingDash();
|
||||
}
|
||||
|
||||
public void OnAimedDashStarted()
|
||||
{
|
||||
// if (WeaponSystem.FlyingState.Active)
|
||||
// {
|
||||
// DashSystem.ShouldMantle = false;
|
||||
// DashSystem.PlannedPlayerLocation = WeaponSystem.GlobalPosition;
|
||||
// }
|
||||
// else if (WeaponSystem.PlantedState.Active)
|
||||
// {
|
||||
// DashSystem.ShouldMantle = false;
|
||||
// var dashLocation = WeaponSystem.PlantLocation;
|
||||
// if (WeaponSystem.IsPlantedInWall())
|
||||
// {
|
||||
// dashLocation += WeaponSystem.PlantNormal * 0.5f; // Player radius
|
||||
// }
|
||||
//
|
||||
// if (WeaponSystem.IsPlantedUnderPlatform())
|
||||
// {
|
||||
// dashLocation += Vector3.Down * 1f; // Player height
|
||||
// }
|
||||
//
|
||||
// DashSystem.PlannedPlayerLocation = dashLocation;
|
||||
// }
|
||||
// _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized();
|
||||
|
||||
// Adjusting for player height, where the middle of the capsule should get to the dash location instead of the
|
||||
// feet of the capsule
|
||||
// GD.Print(DashSystem.CollisionNormal);
|
||||
var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius;
|
||||
var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction;
|
||||
|
||||
var dashTween = GetTree().CreateTween();
|
||||
dashTween.SetParallel();
|
||||
dashTween.SetTrans(Tween.TransitionType.Cubic);
|
||||
dashTween.SetEase(Tween.EaseType.InOut);
|
||||
|
||||
dashTween.TweenProperty(this, "global_position", correctedLocation, AimedDashTime);
|
||||
dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime);
|
||||
|
||||
dashTween.Finished += AimedDashTweenEnded;
|
||||
}
|
||||
|
||||
public void HandleAimedDash(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void AimedDashTweenOngoing(float progress)
|
||||
{
|
||||
}
|
||||
|
||||
public void AimedDashTweenEnded()
|
||||
{
|
||||
_playerState.SendEvent("dash_finished");
|
||||
}
|
||||
|
||||
public void OnAimedDashFinished()
|
||||
{
|
||||
if (DashSystem.ShouldMantle)
|
||||
Mantle();
|
||||
}
|
||||
|
||||
public void OnSimpleDashStarted()
|
||||
{
|
||||
@ -760,7 +864,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
_playerState.SendEvent(EmpoweredActionsLeft <= 0 ? "expired" : "power_used");
|
||||
}
|
||||
|
||||
// Jumping
|
||||
public void StartCoyoteTime()
|
||||
{
|
||||
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
|
||||
@ -769,43 +872,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_playerState.SendEvent("coyote_expired");
|
||||
}
|
||||
public void JumpFromWall(bool isEmpowered)
|
||||
{
|
||||
if (!_isWallJumpAvailable)
|
||||
return;
|
||||
|
||||
_isWallJumpAvailable = false;
|
||||
var wallNormal = WallHugSystem.GetWallNormal().UnwrapOr(Vector3.Up);
|
||||
var isLookingTowardsWall = HeadSystem.GetForwardHorizontalVector().Dot(wallNormal) > 0.5;
|
||||
var jumpDirection = isLookingTowardsWall ? Vector3.Up : wallNormal;
|
||||
if (isEmpowered && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(JumpTypes.JumpFromDash, jumpDirection);
|
||||
return;
|
||||
}
|
||||
PerformJump(JumpTypes.JumpFromWall, jumpDirection);
|
||||
}
|
||||
private void PerformJump(JumpTypes jumpType, Vector3? jumpDirection = null)
|
||||
{
|
||||
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
|
||||
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
|
||||
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
Jump(jumpType, jumpVector);
|
||||
}
|
||||
|
||||
public void Jump(JumpTypes jumpType, Vector3? jumpDirection = null, float boost = 1.0f)
|
||||
{
|
||||
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
|
||||
var jumpForce = 100.0f;
|
||||
|
||||
var currentHorizontalVelocity = new Vector3(Velocity.X, 0, Velocity.Z);
|
||||
var jumpVelocity = jumpForce * effectiveJumpDirection * boost;
|
||||
Velocity = currentHorizontalVelocity + jumpVelocity;
|
||||
}
|
||||
|
||||
// Mantling
|
||||
public void Mantle()
|
||||
@ -847,7 +913,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
_playerState.SendEvent("dash_ended");
|
||||
DashSystem.CancelDash();
|
||||
DashSystem.StopPreparingDash();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -855,7 +921,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
if (WeaponSystem.FlyingState.Active)
|
||||
{
|
||||
DashSystem.ShouldMantle = false;
|
||||
DashSystem.PlannedPlayerLocation = WeaponSystem.GlobalPosition;
|
||||
DashSystem.PlannedLocation = WeaponSystem.GlobalPosition;
|
||||
}
|
||||
else if (WeaponSystem.PlantedState.Active)
|
||||
{
|
||||
@ -871,10 +937,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
dashLocation += Vector3.Down * 1f; // Player height
|
||||
}
|
||||
|
||||
DashSystem.PlannedPlayerLocation = dashLocation;
|
||||
DashSystem.PlannedLocation = dashLocation;
|
||||
}
|
||||
_dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized();
|
||||
DashSystem.Dash();
|
||||
_dashDirection = (DashSystem.PlannedLocation - GlobalPosition).Normalized();
|
||||
}
|
||||
public void OnDashEnded()
|
||||
{
|
||||
@ -916,7 +981,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
DashSystem.CancelDash();
|
||||
DashSystem.StopPreparingDash();
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
|
||||
RemoveChild(WeaponRoot);
|
||||
@ -930,21 +995,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashSystem.CollisionPoint,
|
||||
DashSystem.CollisionNormal);
|
||||
}
|
||||
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)
|
||||
@ -952,13 +1002,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
if (WeaponSystem.InHandState.Active)
|
||||
RotateWeaponWithPlayer();
|
||||
}
|
||||
public void HandleAiming(float delta)
|
||||
{
|
||||
RotateWeaponWithPlayer();
|
||||
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Stateless logic ////////
|
||||
|
Reference in New Issue
Block a user