throwing weapon back on
This commit is contained in:
@ -118,6 +118,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// Dash
|
||||
[ExportGroup("Dash")]
|
||||
[Export(PropertyHint.Range, "0,5,1,or_greater")]
|
||||
public int MaxNumberOfEmpoweredActions { get; set; } = 1;
|
||||
// Simple dash
|
||||
[ExportSubgroup("Simple")]
|
||||
[Export(PropertyHint.Range, "0,50,0.1")]
|
||||
@ -129,9 +131,13 @@ public partial class PlayerController : CharacterBody3D
|
||||
[Export(PropertyHint.Range, "0,100,0.1")]
|
||||
public float PoweredDashStrength { get; set; } = 10f;
|
||||
// Aimed Dash
|
||||
[ExportSubgroup("Aimed")]
|
||||
[ExportSubgroup("Special")]
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float AimedDashTime { get; set; } = 0.1f;
|
||||
[Export(PropertyHint.Range, "0,100,1,or_greater")]
|
||||
public float PostDashSpeed { get; set; } = 100f;
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float TimeScaleAimInAir { get; set; } = 0.05f;
|
||||
|
||||
// Wall hug
|
||||
[ExportGroup("Wall hug")]
|
||||
@ -145,16 +151,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
private float _targetSpeed;
|
||||
private float _gravity;
|
||||
|
||||
[ExportCategory("Other")]
|
||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||
public float TimeScaleAimInAir { get; set; } = 0.05f;
|
||||
[Export(PropertyHint.Range, "0,5,1,or_greater")]
|
||||
public int MaxNumberOfDashActions { get; set; } = 1;
|
||||
|
||||
[Export]
|
||||
public Curve DashTimeDilationCurve { get; set; }
|
||||
private bool _canDash = true;
|
||||
|
||||
private int _empoweredActionsLeft;
|
||||
public int EmpoweredActionsLeft
|
||||
{
|
||||
@ -167,7 +163,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
|
||||
private bool _isWallJumpAvailable = true;
|
||||
private bool _isActionPerfectlyTimed = false;
|
||||
private bool _canDash = true;
|
||||
private bool _shouldMantleOnDashEnded = false;
|
||||
|
||||
private StateChart _playerState;
|
||||
|
||||
@ -217,7 +214,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
// DashIndicator = GetNode<TextureRect>("%DashIndicator");
|
||||
PowerCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
|
||||
PowerCooldownIndicator.Visible = false;
|
||||
EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
EmpoweredActionsLeft = MaxNumberOfEmpoweredActions;
|
||||
_targetSpeed = WalkSpeed;
|
||||
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
@ -330,7 +327,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
Stamina.SetSpeeds(WalkSpeed, WalkSpeed);
|
||||
|
||||
EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
EmpoweredActionsLeft = MaxNumberOfEmpoweredActions;
|
||||
|
||||
///////////////////////////
|
||||
// Signal setup ///////////
|
||||
@ -374,7 +371,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
_poweredDash.StateExited += OnPoweredDashFinished;
|
||||
|
||||
_aimedDash.StateEntered += OnAimedDashStarted;
|
||||
_aimedDash.StatePhysicsProcessing += HandleAimedDash;
|
||||
_aimedDash.StateExited += OnAimedDashFinished;
|
||||
|
||||
_simpleDashCooldownTimer.Timeout += DashCooldownTimeout;
|
||||
@ -432,6 +428,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
}
|
||||
public void HandleWallHanging(float delta)
|
||||
{
|
||||
GD.Print("Hanging");
|
||||
WallHang(delta);
|
||||
}
|
||||
|
||||
@ -443,27 +440,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap());
|
||||
return;
|
||||
}
|
||||
|
||||
// if (_grounded.Active || _coyoteEnabled.Active)
|
||||
// {
|
||||
// if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
// {
|
||||
// PerformEmpoweredAction();
|
||||
// PerformJump(JumpTypes.JumpFromDash);
|
||||
// _playerState.SendEvent("megajump");
|
||||
// }
|
||||
// }
|
||||
// else if (_doubleJumpEnabled.Active)
|
||||
// if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
// {
|
||||
// PerformEmpoweredAction();
|
||||
// PerformJump(JumpTypes.JumpFromDash);
|
||||
// _playerState.SendEvent("megajump");
|
||||
// }
|
||||
// else
|
||||
// PerformJump(JumpTypes.DoubleJump);
|
||||
// else if (_onWall.Active)
|
||||
// JumpFromWall(_empowerOn.Active);
|
||||
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
@ -633,7 +609,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
public void PowerCooldownExpired()
|
||||
{
|
||||
EmpoweredActionsLeft += 1;
|
||||
var eventToSend = EmpoweredActionsLeft == MaxNumberOfDashActions ? "fully_charged" : "recharge";
|
||||
var eventToSend = EmpoweredActionsLeft == MaxNumberOfEmpoweredActions ? "fully_charged" : "recharge";
|
||||
_playerState.SendEvent(eventToSend);
|
||||
}
|
||||
|
||||
@ -655,10 +631,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
_playerState.SendEvent("aim_pressed");
|
||||
// if (!WeaponSystem.InHandState.Active)
|
||||
// {
|
||||
// OnDashStarted();
|
||||
// }
|
||||
}
|
||||
public void OnInputAimDown()
|
||||
{
|
||||
@ -677,7 +649,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
if (_aiming.Active)
|
||||
{
|
||||
OnWeaponThrown();
|
||||
ThrowWeapon();
|
||||
}
|
||||
}
|
||||
public void OnInputEmpowerDown()
|
||||
@ -688,7 +660,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
_playerState.SendEvent("empower_released");
|
||||
}
|
||||
|
||||
public void OnInputDashPressed()
|
||||
{
|
||||
if (_aiming.Active && CanPerformEmpoweredAction())
|
||||
@ -714,18 +685,25 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
_playerState.SendEvent("dash");
|
||||
}
|
||||
|
||||
public void OnAimingEntered()
|
||||
{
|
||||
// if (!WeaponSystem.InHandState.Active)
|
||||
// {
|
||||
// OnDashStarted();
|
||||
// return;
|
||||
// }
|
||||
if (CanPerformEmpoweredAction())
|
||||
DashSystem.StartPreparingDash();
|
||||
if (!CanPerformEmpoweredAction())
|
||||
return;
|
||||
|
||||
if (!isOnFloorCustom() && CanPerformEmpoweredAction())
|
||||
if (WeaponSystem.FlyingState.Active)
|
||||
{
|
||||
DashToFlyingWeapon();
|
||||
return;
|
||||
}
|
||||
|
||||
if (WeaponSystem.PlantedState.Active)
|
||||
{
|
||||
DashToPlantedWeapon();
|
||||
return;
|
||||
}
|
||||
|
||||
DashSystem.StartPreparingDash();
|
||||
if (!isOnFloorCustom())
|
||||
ReduceTimeScaleWhileAiming();
|
||||
}
|
||||
public void HandleAiming(float delta)
|
||||
@ -740,41 +718,75 @@ public partial class PlayerController : CharacterBody3D
|
||||
DashSystem.StopPreparingDash();
|
||||
}
|
||||
|
||||
private bool _shouldMantleOnDashEnded = false;
|
||||
public void DashToFlyingWeapon()
|
||||
{
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
_playerState.SendEvent("weapon_dash");
|
||||
PerformEmpoweredAction();
|
||||
|
||||
DashSystem.ShouldMantle = false;
|
||||
_dashDirection = (WeaponSystem.GlobalPosition - GlobalPosition).Normalized();
|
||||
|
||||
var dashTween = CreatePositionTween(WeaponSystem.GlobalPosition, AimedDashTime);
|
||||
dashTween.Finished += DashToFlyingWeaponTweenEnded;
|
||||
}
|
||||
|
||||
public void DashToFlyingWeaponTweenEnded()
|
||||
{
|
||||
// Get the weapon back
|
||||
GetTree().GetRoot().RemoveChild(WeaponRoot);
|
||||
AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
WeaponSystem.ResetWeapon();
|
||||
|
||||
var vel = _dashDirection * PostDashSpeed;
|
||||
SetVelocity(vel);
|
||||
_playerState.SendEvent("dash_finished");
|
||||
}
|
||||
|
||||
public void DashToPlantedWeapon()
|
||||
{
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
_playerState.SendEvent("weapon_dash");
|
||||
PerformEmpoweredAction();
|
||||
|
||||
DashSystem.ShouldMantle = false;
|
||||
var dashLocation = WeaponSystem.PlantLocation;
|
||||
if (WeaponSystem.IsPlantedInWall())
|
||||
dashLocation += WeaponSystem.PlantNormal * _playerRadius;
|
||||
if (WeaponSystem.IsPlantedUnderPlatform())
|
||||
dashLocation += Vector3.Down * _playerHeight;
|
||||
|
||||
var dashTween = CreatePositionTween(dashLocation, AimedDashTime);
|
||||
dashTween.Finished += DashToPlantedWeaponTweenEnded;
|
||||
}
|
||||
|
||||
public void DashToPlantedWeaponTweenEnded()
|
||||
{
|
||||
// Store the weapon state before resetting it
|
||||
var isPlantedOnWall = WeaponSystem.IsPlantedInWall();
|
||||
var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform();
|
||||
var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform;
|
||||
|
||||
// Get the weapon back
|
||||
GetTree().GetRoot().RemoveChild(WeaponRoot);
|
||||
AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
WeaponSystem.ResetWeapon();
|
||||
|
||||
var resultingEvent = shouldDashToHanging ? "to_planted" : "dash_finished";
|
||||
_playerState.SendEvent(resultingEvent);
|
||||
}
|
||||
|
||||
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 = CreatePositionTween(correctedLocation, AimedDashTime);
|
||||
dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime);
|
||||
// dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime);
|
||||
dashTween.Finished += AimedDashTweenEnded;
|
||||
|
||||
_shouldMantleOnDashEnded = DashSystem.ShouldMantle;
|
||||
@ -791,19 +803,27 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public void HandleAimedDash(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void AimedDashTweenOngoing(float progress)
|
||||
{
|
||||
}
|
||||
|
||||
public void AimedDashTweenEnded()
|
||||
{
|
||||
_playerState.SendEvent("dash_finished");
|
||||
}
|
||||
|
||||
public void ThrowWeapon()
|
||||
{
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
|
||||
RemoveChild(WeaponRoot);
|
||||
GetTree().GetRoot().AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
|
||||
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation;
|
||||
WeaponSystem.ThrowWeapon(
|
||||
weaponTargetLocation,
|
||||
DashSystem.HasHit,
|
||||
DashSystem.CollisionPoint,
|
||||
DashSystem.CollisionNormal);
|
||||
}
|
||||
|
||||
public void OnAimedDashFinished()
|
||||
{
|
||||
@ -848,7 +868,9 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void OnPoweredDashFinished()
|
||||
{
|
||||
// Try mantling here
|
||||
// Try mantling but don't know if this is useful
|
||||
if (CanMantle())
|
||||
MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap());
|
||||
}
|
||||
|
||||
public void FinishPoweredDash()
|
||||
@ -902,96 +924,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
_playerState.SendEvent("grounded");
|
||||
}
|
||||
|
||||
// Dashing and weapon throwing
|
||||
public void OnDashStarted()
|
||||
{
|
||||
if (!CanPerformEmpoweredAction())
|
||||
{
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
_playerState.SendEvent("dash_ended");
|
||||
DashSystem.StopPreparingDash();
|
||||
return;
|
||||
}
|
||||
|
||||
PerformEmpoweredAction();
|
||||
if (WeaponSystem.FlyingState.Active)
|
||||
{
|
||||
DashSystem.ShouldMantle = false;
|
||||
DashSystem.PlannedLocation = 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.PlannedLocation = dashLocation;
|
||||
}
|
||||
_dashDirection = (DashSystem.PlannedLocation - GlobalPosition).Normalized();
|
||||
}
|
||||
public void OnDashEnded()
|
||||
{
|
||||
// Regular dash
|
||||
if (WeaponSystem.InHandState.Active)
|
||||
{
|
||||
_playerState.SendEvent("dash_ended");
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the weapon state before resetting it
|
||||
var isPlantedOnWall = WeaponSystem.IsPlantedInWall();
|
||||
var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform();
|
||||
var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform;
|
||||
var isFlying = WeaponSystem.FlyingState.Active;
|
||||
|
||||
// Get the weapon back
|
||||
GetTree().GetRoot().RemoveChild(WeaponRoot);
|
||||
AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
WeaponSystem.ResetWeapon();
|
||||
|
||||
if (isFlying)
|
||||
{
|
||||
var vel = _dashDirection * DashSystem.PostDashSpeed;
|
||||
SetVelocity(vel);
|
||||
_playerState.SendEvent("dash_ended");
|
||||
return; // In case states aren't exclusives
|
||||
}
|
||||
|
||||
if (shouldDashToHanging)
|
||||
{
|
||||
_playerState.SendEvent("dash_to_planted");
|
||||
return; // In case states aren't exclusives
|
||||
}
|
||||
|
||||
// Weapon planted anywhere else
|
||||
_playerState.SendEvent("dash_ended");
|
||||
}
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
DashSystem.StopPreparingDash();
|
||||
_playerState.SendEvent("cancel_aim");
|
||||
|
||||
RemoveChild(WeaponRoot);
|
||||
GetTree().GetRoot().AddChild(WeaponRoot);
|
||||
WeaponRoot.SetGlobalPosition(GlobalPosition);
|
||||
|
||||
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation;
|
||||
WeaponSystem.ThrowWeapon(
|
||||
weaponTargetLocation,
|
||||
DashSystem.HasHit,
|
||||
DashSystem.CollisionPoint,
|
||||
DashSystem.CollisionNormal);
|
||||
}
|
||||
|
||||
// Regular processes
|
||||
public void HandleWeaponInHand(float delta)
|
||||
{
|
||||
@ -1142,10 +1074,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
///////////////////////////
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
|
||||
LookAround();
|
||||
// MoveAround(delta);
|
||||
CameraModifications((float) delta);
|
||||
HandleStairs((float) delta);
|
||||
}
|
||||
|
Reference in New Issue
Block a user