Files
MovementTests/player_controller/Scripts/PlayerController.cs
Minimata 6c2ad89687
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 19s
Create tag and build when new code gets to main / Export (push) Successful in 9m42s
fixing the manlting into geo
2026-01-06 12:36:38 +01:00

1399 lines
42 KiB
C#

using System;
using Godot;
using GodotStateCharts;
using Movementtests.addons.godot_state_charts.csharp;
using Movementtests.systems;
using Movementtests.player_controller.Scripts;
using RustyOptions;
public partial class PlayerController : CharacterBody3D
{
public enum AllowedInputs
{
All,
MoveCamera,
None,
}
private bool _isUsingGamepad;
// User API to important child nodes.
public HeadSystem HeadSystem;
public Bobbing Bobbing;
public FieldOfView FieldOfView;
public StairsSystem StairsSystem;
public MantleSystem MantleSystem;
public DashSystem DashSystem;
public CapsuleCollider CapsuleCollider;
public Node3D WeaponRoot;
public WeaponSystem WeaponSystem;
public WallHugSystem WallHugSystem;
public PlayerUi PlayerUi;
public TextureRect DashIndicator;
public ColorRect PowerCooldownIndicator;
public Node3D DashIndicatorNode;
public MeshInstance3D DashIndicatorMesh;
public CylinderMesh DashIndicatorMeshCylinder;
public RayCast3D WallRunSnapper;
private bool _movementEnabled = true;
private Vector3 _dashDirection = Vector3.Zero;
private bool _shouldMantle;
private Vector3 _mantleLocation = Vector3.Zero;
private Vector3 _preMantleVelocity = Vector3.Zero;
private float _lastFrameWasOnFloor = -Mathf.Inf;
private const int NUM_OF_HEAD_COLLISION_DETECTORS = 4;
private RayCast3D[] _headCollisionDetectors;
private Vector3 _inputMove = Vector3.Zero;
private Vector3 _inputMoveKeyboard = Vector3.Zero;
private float _inputRotateY;
private float _inputRotateFloorplane;
private int _framesSinceJumpAtApex;
// Timers
private Timer _timeScaleAimInAirTimer;
private Timer _simpleDashCooldownTimer;
private Timer _powerCooldownTimer;
[Export] public Marker3D TutorialWeaponTarget;
[Export] public bool TutorialDone { get; set; }
[ExportCategory("Movement")]
[ExportGroup("Ground")]
[Export(PropertyHint.Range, "0,20,0.1,or_greater")]
public float WalkSpeed { get; set; } = 7.0f;
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
public float AccelerationFloor = 5.0f;
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
public float DecelerationFloor = 5.0f;
[ExportGroup("Air")]
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
public float AccelerationAir = 3.0f;
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
public float DecelerationAir = 1.0f;
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
public float Weight { get; set; } = 3.0f;
[ExportGroup("Mantle")]
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float MantleTime { get; set; } = 0.1f;
[Export]
public PackedScene MantlePath { get; set; }
// Jump
[ExportGroup("Jump")]
[Export(PropertyHint.Range, "0,1,0.01")]
public float CoyoteTime { get; set; } = 0.2f;
// Simple jump
[ExportSubgroup("Simple jump")]
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float SimpleJumpStartVelocity { get; set; } = 3.0f;
[Export(PropertyHint.Range, "0,10,1,or_greater")]
public int SimpleJumpHangTimeInFrames { get; set; } = 5;
[Export(PropertyHint.Range, "1,10,0.1,or_greater")]
public float SimpleJumpGravityLesseningFactor { get; set; } = 3f;
// Double jump
[ExportSubgroup("Double jump")]
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float DoubleJumpStartVelocity { get; set; } = 10.0f;
[Export(PropertyHint.Range, "0,10,1,or_greater")]
public int DoubleJumpHangTimeInFrames { get; set; } = 5;
[Export(PropertyHint.Range, "1,10,0.1,or_greater")]
public float DoubleJumpGravityLesseningFactor { get; set; } = 3f;
// Mega jump
[ExportSubgroup("Mega jump")]
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float MegaJumpStartVelocity { get; set; } = 10.0f;
[Export(PropertyHint.Range, "0,10,1,or_greater")]
public int MegaJumpHangTimeInFrames { get; set; } = 5;
[Export(PropertyHint.Range, "1,10,0.1,or_greater")]
public float MegaJumpGravityLesseningFactor { get; set; } = 3f;
// Wall jump
[ExportSubgroup("Wall jump")]
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float WallJumpStartVelocity { get; set; } = 10.0f;
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float WallMegajumpStartVelocity { get; set; } = 20.0f;
// 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")]
public float SimpleDashStrength { get; set; } = 10f;
// Powered Dash
[ExportSubgroup("Powered")]
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float PoweredDashTime { get; set; } = 0.3f;
[Export(PropertyHint.Range, "0,100,0.1")]
public float PoweredDashStrength { get; set; } = 10f;
// Aimed Dash
[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")]
[Export(PropertyHint.Range, "0,50,0.1,or_greater")]
public float WallHugGravityLesseningFactor { get; set; } = 2f;
[Export(PropertyHint.Range, "0.1,50,0.1,or_greater")]
public float WallHugDownwardMaxSpeed { get; set; } = 2f;
[Export(PropertyHint.Range, "0.1,10,0.1,or_greater")]
public float WallHugHorizontalDeceleration { get; set; } = 5f;
// Wall run
[ExportGroup("Wall run")]
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
public float WallRunUpwardVelocity { get; set; } = 10f;
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
public float WallRunAltitudeLossSpeed { get; set; } = 10f;
[Export(PropertyHint.Range, "1,20,0.1,or_greater")]
public float WallRunSpeedThreshold { get; set; } = 8f;
private float _targetSpeed;
private float _gravity;
private int _empoweredActionsLeft;
public int EmpoweredActionsLeft
{
get => _empoweredActionsLeft;
set
{
_empoweredActionsLeft = value;
PlayerUi.SetNumberOfDashesLeft(value);
}
}
public AllowedInputs CurrentlyAllowedInputs { get; set; } = AllowedInputs.All;
private bool _canDashAirborne = true;
private bool _isWallJumpAvailable = true;
private bool _canDash = true;
private bool _shouldMantleOnDashEnded;
private Vector3 _wallHugStartLocation = Vector3.Zero;
private Vector3 _wallHugStartNormal = Vector3.Zero;
private Vector3 _wallHugStartProjectedVelocity = Vector3.Zero;
private Vector3 _currentWallContactPoint = Vector3.Zero;
private StateChart _playerState;
private StateChartState _aiming;
private StateChartState _empowerOn;
private StateChartState _powerExpired;
private StateChartState _powerRecharging;
private StateChartState _powerFull;
private StateChartState _grounded;
private StateChartState _airborne;
private StateChartState _coyoteEnabled;
// private StateChartState _doubleJumpEnabled;
private StateChartState _simpleJump;
private StateChartState _doubleJump;
private StateChartState _megaJump;
private StateChartState _mantling;
private StateChartState _simpleDash;
private StateChartState _poweredDash;
private StateChartState _aimedDash;
private StateChartState _onWall;
private StateChartState _onWallHugging;
private StateChartState _onWallHuggingCoyoteEnabled;
private StateChartState _onWallHanging;
private StateChartState _onWallRunning;
private StateChartState _onWallRunningCoyoteEnabled;
private Transition _onJumpFromWallCoyote;
private Transition _onJumpFromWallRunCoyote;
private Transition _onJumpFromWall1;
private Transition _onJumpFromWall2;
private Transition _onJumpFromWall3;
private Transition _onMegajumpFromWall;
private Transition _onLeaveWallFromRunCoyote;
private Transition _onLeaveWallFromRun;
private float _playerHeight;
private float _playerRadius;
private bool _isJumpInputPressed;
private float _lookSensitivityMultiplier = 1.0f;
private float _mouseSensitivityMultiplier = 1.0f;
private float _headBobbingMultiplier = 1.0f;
private float _fovChangeMultiplier = 1.0f;
public override void _Ready()
{
LoadSettings();
///////////////////////////
// Getting components /////
///////////////////////////
// General use stuff
PlayerUi = GetNode<PlayerUi>("UI");
// DashIndicator = GetNode<TextureRect>("%DashIndicator");
PowerCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
PowerCooldownIndicator.Visible = false;
EmpoweredActionsLeft = MaxNumberOfEmpoweredActions;
_targetSpeed = WalkSpeed;
DashIndicatorNode = GetNode<Node3D>("DashIndicator");
DashIndicatorMesh = GetNode<MeshInstance3D>("DashIndicator/DashIndicatorMesh");
DashIndicatorMeshCylinder = DashIndicatorMesh.Mesh as CylinderMesh;
DashIndicatorMesh.Visible = false;
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
// Camera stuff
HeadSystem = GetNode<HeadSystem>("HeadSystem");
Bobbing = GetNode<Bobbing>("Bobbing");
FieldOfView = GetNode<FieldOfView>("FieldOfView");
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
// Movement stuff
WeaponRoot = GetNode<Node3D>("WeaponRoot");
WeaponSystem = GetNode<WeaponSystem>("WeaponRoot/WeaponSystem");
MantleSystem = GetNode<MantleSystem>("HeadSystem/MantleSystem");
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
DashSystem = GetNode<DashSystem>("DashSystem");
StairsSystem = GetNode<StairsSystem>("StairsSystem");
WallHugSystem = GetNode<WallHugSystem>("WallHugSystem");
WallRunSnapper = GetNode<RayCast3D>("%WallRunSnapper");
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
{
_headCollisionDetectors[i] = GetNode<RayCast3D>(
"HeadCollisionDetectors/HeadCollisionDetector" + i);
}
var playerShape = CapsuleCollider.GetShape() as CapsuleShape3D;
_playerHeight = playerShape!.Height;
_playerRadius = playerShape.Radius;
// State managementb
_playerState = StateChart.Of(GetNode("StateChart"));
_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"));
_powerExpired = StateChartState.Of(GetNode("StateChart/Root/PowerReserve/Expired"));
_powerRecharging = StateChartState.Of(GetNode("StateChart/Root/PowerReserve/AtLeastOneCharge"));
_powerFull = StateChartState.Of(GetNode("StateChart/Root/PowerReserve/Full"));
_grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded"));
_airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne"));
_coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled"));
// _doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled"));
_simpleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/SimpleJump"));
_doubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/DoubleJump"));
_megaJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/MegaJump"));
_mantling = StateChartState.Of(GetNode("StateChart/Root/Movement/Mantling"));
_onJumpFromWallCoyote = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/HuggingCoyoteEnabled/OnJump"));
_onJumpFromWallRunCoyote = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/RunningCoyoteEnabled/OnJump"));
_onJumpFromWall1 = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/Hugging/OnJump"));
_onJumpFromWall2 = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/Hanging/OnJump"));
_onJumpFromWall3 = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/Running/OnJump"));
_onMegajumpFromWall = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/OnMegajump"));
_onWall = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall"));
_onWallHuggingCoyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/HuggingCoyoteEnabled"));
_onWallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hugging"));
_onWallHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hanging"));
_onWallRunning = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Running"));
_onWallRunningCoyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/RunningCoyoteEnabled"));
_onLeaveWallFromRun = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/Running/OnLeaveWall"));
_onLeaveWallFromRunCoyote = Transition.Of(GetNode("StateChart/Root/Movement/OnWall/RunningCoyoteEnabled/OnLeaveWall"));
// State timers
_powerCooldownTimer = GetNode<Timer>("PowerCooldown");
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
_simpleDashCooldownTimer = GetNode<Timer>("DashCooldown");
///////////////////////////
// Initialize components //
///////////////////////////
// Camera stuff
HeadSystem.Init();
Bobbing.Init(camera);
FieldOfView.Init(camera);
// Movement stuff
// Getting universal setting from GODOT editor to be in sync
_gravity = (float)ProjectSettings.GetSetting("physics/3d/default_gravity");
MantleSystem.Init();
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
DashSystem.Init(HeadSystem, camera);
WeaponSystem.Init(HeadSystem, camera);
WallHugSystem.Init();
// RPG Stuff
EmpoweredActionsLeft = MaxNumberOfEmpoweredActions;
if (!TutorialDone)
PlaceWeaponForTutorial();
///////////////////////////
// Signal setup ///////////
///////////////////////////
_aiming.StatePhysicsProcessing += HandleAiming;
_aiming.StateEntered += OnAimingEntered;
_aiming.StateExited += ResetTimeScale;
_aiming.StateExited += OnAimingExited;
_grounded.StateEntered += OnGrounded;
_grounded.StatePhysicsProcessing += HandleGrounded;
_airborne.StatePhysicsProcessing += HandleAirborne;
_onWall.StatePhysicsProcessing += HandleOnWall;
_coyoteEnabled.StateEntered += StartCoyoteTime;
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
_powerFull.StateEntered += StopPowerCooldown;
_powerFull.StateExited += StartPowerCooldown;
_powerRecharging.StateEntered += StartPowerCooldown;
_powerCooldownTimer.Timeout += PowerCooldownExpired;
_powerRecharging.StateProcessing += PowerRecharging;
_powerExpired.StateProcessing += PowerRecharging;
_simpleJump.StateEntered += OnSimpleJumpStarted;
_simpleJump.StatePhysicsProcessing += HandleSimpleJump;
_doubleJump.StateEntered += OnDoubleJumpStarted;
_doubleJump.StatePhysicsProcessing += HandleDoubleJump;
_megaJump.StateEntered += OnMegaJumpStarted;
_megaJump.StatePhysicsProcessing += HandleMegaJump;
_mantling.StateEntered += OnMantleStarted;
_mantling.StatePhysicsProcessing += HandleMantling;
_simpleDash.StateEntered += OnSimpleDashStarted;
_simpleDash.StatePhysicsProcessing += HandleSimpleDash;
_poweredDash.StateEntered += OnPoweredDashStarted;
_poweredDash.StatePhysicsProcessing += HandlePoweredDash;
_poweredDash.StateExited += OnPoweredDashFinished;
_aimedDash.StateEntered += OnAimedDashStarted;
_aimedDash.StateExited += OnAimedDashFinished;
_simpleDashCooldownTimer.Timeout += DashCooldownTimeout;
_onWall.StateEntered += OnWallStarted;
_onWall.StateExited += OnWallStopped;
_onWallHuggingCoyoteEnabled.StateEntered += OnWallHuggingStarted;
_onWallHuggingCoyoteEnabled.StatePhysicsProcessing += HandleWallHugging;
_onWallHugging.StatePhysicsProcessing += HandleWallHugging;
_onWallHanging.StatePhysicsProcessing += HandleWallHanging;
_onWallRunningCoyoteEnabled.StateEntered += OnWallRunningStarted;
_onWallRunningCoyoteEnabled.StatePhysicsProcessing += HandleWallRunning;
_onWallRunning.StatePhysicsProcessing += HandleWallRunning;
_onJumpFromWallCoyote.Taken += OnJumpFromWallCoyote;
_onJumpFromWallRunCoyote.Taken += OnJumpFromWallCoyote;
_onJumpFromWall1.Taken += OnJumpFromWall;
_onJumpFromWall2.Taken += OnJumpFromWall;
_onJumpFromWall3.Taken += OnJumpFromWall;
_onMegajumpFromWall.Taken += OnMegajumpFromWall;
_onLeaveWallFromRun.Taken += OnLeaveWallFromRun;
_onLeaveWallFromRunCoyote.Taken += OnLeaveWallFromRun;
}
public void SetAllowedInputsAll()
{
CurrentlyAllowedInputs = AllowedInputs.All;
}
public void SetAllowedInputsMoveCamera()
{
CurrentlyAllowedInputs = AllowedInputs.MoveCamera;
}
public void SetAllowedInputsNone()
{
CurrentlyAllowedInputs = AllowedInputs.None;
}
public void LoadSettings()
{
var config = new ConfigFile();
// Load data from a file.
Error err = config.Load("user://config.cfg");
// If the file didn't load, ignore it.
if (err != Error.Ok)
{
throw new Exception("Couldn't load config.cfg");
}
_lookSensitivityMultiplier = (float) config.GetValue("InputSettings", "LookSensitivity", 1.0f);
_mouseSensitivityMultiplier = (float) config.GetValue("InputSettings", "MouseSensitivity", 1.0f);
_headBobbingMultiplier = (float) config.GetValue("InputSettings", "HeadBobbingWhileWalking", 1.0f);
_fovChangeMultiplier = (float) config.GetValue("InputSettings", "FovChangeWithSpeed", 1.0f);
}
public void OnTutorialDone(Node3D _)
{
TutorialDone = true;
}
public void OnGrounded()
{
_isWallJumpAvailable = true;
_canDashAirborne = true;
if (_simpleDashCooldownTimer.IsStopped())
_simpleDashCooldownTimer.Start();
}
public void DashCooldownTimeout()
{
_canDash = true;
}
public bool IsTryingToMantle()
{
return MantleSystem.IsMantlePossible && GetMoveInput().Z < -0.5f && _isJumpInputPressed;
}
public void HandleGrounded(float delta)
{
MoveOnGround(delta);
// if (IsTryingToMantle()) _playerState.SendEvent("mantle");
if (!isOnFloorCustom())
_playerState.SendEvent("start_falling");
}
public void HandleAirborne(float delta)
{
MoveInAir(delta);
if (isOnFloorCustom())
_playerState.SendEvent("grounded");
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
if (!WallHugSystem.IsWallHugging())
{
_isWallJumpAvailable = true; // reset wall jump if we left the wall
return;
}
// Going upwards, we stay simply airborne
if (Velocity.AngleTo(Vector3.Up) < Math.PI / 4)
return;
// Should we start a wall run
var wallNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Zero);
var isIndeedWall = wallNormal.Y < 0.1;
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
var hvelProjected = hvel.Slide(_wallHugStartNormal);
var haveEnoughSpeed = hvelProjected.Length() > WallRunSpeedThreshold;
var isCoplanarEnough = Velocity.AngleTo(wallNormal) > Math.PI/4 && Velocity.AngleTo(wallNormal) < 3*Math.PI/4;
var isGoingDownwards = Velocity.AngleTo(Vector3.Down) < Math.PI/4;
if (haveEnoughSpeed && isCoplanarEnough && !isGoingDownwards && isIndeedWall && !_coyoteEnabled.Active)
{
SetVerticalVelocity(WallRunUpwardVelocity);
_playerState.SendEvent("wall_run");
return;
}
// If all else fail and we go down, we hug
if (Velocity.Y < 0 && !_coyoteEnabled.Active)
{
_playerState.SendEvent("wall_hug");
}
}
public void HandleOnWall(float delta)
{
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
}
public void OnWallHuggingStarted()
{
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
}
public void OnWallRunningStarted()
{
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
}
public void OnWallDetected()
{
FinishPoweredDash();
if (!_onWall.Active)
return;
var newWallNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Up);
if (newWallNormal.AngleTo(_wallHugStartNormal) > Mathf.Pi/4) return;
_wallHugStartNormal = newWallNormal;
}
public void OnWallStarted()
{
if (!WallHugSystem.IsWallHugging())
return;
_wallHugStartNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Up);
_currentWallContactPoint = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero);
_wallHugStartLocation = _currentWallContactPoint + _wallHugStartNormal * _playerRadius;
_wallHugStartProjectedVelocity = Velocity.Slide(_wallHugStartNormal);
}
public void OnWallStopped()
{
}
public void OnLeaveWallFromRun()
{
SimpleDashInDirection(Velocity.Normalized());
}
public void HandleWallHugging(float delta)
{
WallHug(delta);
if (isOnFloorCustom())
_playerState.SendEvent("grounded");
if (!WallHugSystem.IsWallHugging())
{
_playerState.SendEvent("start_falling");
}
}
public void HandleWallHanging(float delta)
{
WallHang(delta);
}
public void HandleWallRunning(float delta)
{
// Find horizontal velocity projected on the current wall
var hvel = new Vector3(Velocity.X, 0, Velocity.Z);
var hvelProjected = hvel.Slide(_wallHugStartNormal);
// Reorient horizontal velocity so we keep it coplanar with the wall without losing speed
var finalHVel = hvelProjected.Normalized() * hvel.Length();
// Adapt vertical speed
var verticalSpeed = Velocity.Y - WallRunAltitudeLossSpeed * delta;
Velocity = finalHVel + Vector3.Up*verticalSpeed;
Velocity *= 0.995f;
_currentWallContactPoint = WallHugSystem.WallHugLocation.UnwrapOr(Vector3.Zero);
if (isOnFloorCustom())
_playerState.SendEvent("grounded");
if (!WallHugSystem.IsWallHugging() || Velocity.Length() < WallRunSpeedThreshold)
{
_playerState.SendEvent("start_falling");
}
}
public void WallHug(float delta)
{
var hvel = ComputeHVelocity(delta, WallHugHorizontalDeceleration, WallHugHorizontalDeceleration);
var hvelProjected = hvel.Slide(_wallHugStartNormal);
var vvel = Velocity.Y - (CalculateGravityForce() * delta / WallHugGravityLesseningFactor);
vvel = Math.Abs(vvel) > WallHugDownwardMaxSpeed ? -WallHugDownwardMaxSpeed : vvel;
Velocity = hvelProjected + vvel*Vector3.Up;
}
public void WallHang(float delta)
{
Velocity = Vector3.Zero;
GlobalPosition = _wallHugStartLocation;
}
// Jump
public void OnInputJumpStarted()
{
_isJumpInputPressed = true;
if (MantleSystem.IsMantlePossible)
{
_playerState.SendEvent("mantle");
return;
}
if (_empowerOn.Active && CanPerformEmpoweredAction())
{
_playerState.SendEvent("megajump");
return;
}
if (_onWallHuggingCoyoteEnabled.Active || _onWallRunningCoyoteEnabled.Active)
{
if (!_isWallJumpAvailable)
{
OnJumpFromWall();
}
}
_playerState.SendEvent("jump");
}
public void OnInputJumpOngoing()
{
}
public void OnInputJumpEnded()
{
_isJumpInputPressed = false;
_playerState.SendEvent("jump_ended");
}
public void OnJumpStarted(float verticalVelocity)
{
_framesSinceJumpAtApex = 0;
SetVerticalVelocity(verticalVelocity);
}
public void OnSimpleJumpStarted()
{
OnJumpStarted(SimpleJumpStartVelocity);
}
public void OnDoubleJumpStarted()
{
_canDash = true;
_canDashAirborne = true;
OnJumpStarted(DoubleJumpStartVelocity);
}
public void OnMegaJumpStarted()
{
PerformEmpoweredAction();
OnJumpStarted(MegaJumpStartVelocity);
}
public void ComputeJumpFromWallHSpeed(float jumpStrength)
{
// if (!_isWallJumpAvailable)
// return;
// _isWallJumpAvailable = false;
// var isLookingTowardsWall = HeadSystem.GetForwardHorizontalVector().Dot(wallNormal) > 0.5;
// var jumpDirection = isLookingTowardsWall ? Vector3.Up : wallNormal;
var wallNormal = WallHugSystem.WallHugNormal.UnwrapOr(Vector3.Up);
var jumpVector = wallNormal * jumpStrength;
var currentHorizontalVelocity = new Vector2(Velocity.X, Velocity.Z);
var wallJumpHorizontalVelocity = new Vector2(jumpVector.X, jumpVector.Z);
SetHorizontalVelocity(currentHorizontalVelocity + wallJumpHorizontalVelocity);
}
public void OnJumpFromWallCoyote()
{
_isWallJumpAvailable = false;
}
public void OnJumpFromWall()
{
ComputeJumpFromWallHSpeed(WallJumpStartVelocity);
}
public void OnMegajumpFromWall()
{
ComputeJumpFromWallHSpeed(WallMegajumpStartVelocity);
}
public void InputDeviceChanged(bool isUsingGamepad)
{
_isUsingGamepad = isUsingGamepad;
}
public Vector3 GetMoveInput()
{
if (_isUsingGamepad)
return _inputMove;
return _inputMoveKeyboard;
}
public Vector3 GetGlobalMoveInput()
{
return Transform.Basis * HeadSystem.Transform.Basis * GetMoveInput();
}
public Vector3 ComputeHVelocity(float delta, float accelerationFactor, float decelerationFactor, Vector3? direction = null)
{
var dir = direction ?? GetGlobalMoveInput();
var acceleration = dir.Length() > 0 ? accelerationFactor : decelerationFactor;
float xAcceleration = Mathf.Lerp(Velocity.X, dir.X * _targetSpeed, delta * acceleration);
float zAcceleration = Mathf.Lerp(Velocity.Z, dir.Z * _targetSpeed, delta * acceleration);
return new Vector3(xAcceleration, 0, zAcceleration);
}
public Vector3 ComputeHVelocityGround(float delta)
{
return ComputeHVelocity(delta, AccelerationFloor, DecelerationFloor);
}
public Vector3 ComputeHVelocityAir(float delta)
{
return ComputeHVelocity(delta, AccelerationAir, DecelerationAir);
}
public void SetVerticalVelocity(float verticalVelocity)
{
Velocity = new Vector3(
x: Velocity.X,
y: verticalVelocity,
z: Velocity.Z);
}
public void SetHorizontalVelocity(Vector2 velocity)
{
Velocity = new Vector3(
x: velocity.X,
y: Velocity.Y,
z: velocity.Y);
}
private Path _mantlePath;
private bool _customMantle;
private Transform3D _customMantleStartTransform;
private Curve3D _customMantleCurve;
private Vector3 _mantleStartPosition;
public void OnMantleStarted()
{
HeadSystem.OnMantle();
_mantlePath = MantlePath.Instantiate() as Path;
if (_mantlePath == null)
{
GD.PrintErr("Failed to instantiate MantlePath");
return;
}
var transform = _customMantle ? _customMantleStartTransform : MantleSystem.GlobalTransform;
var curve = _customMantle ? _customMantleCurve : MantleSystem.MantleCurve;
GetTree().GetRoot().AddChild(_mantlePath);
_mantlePath.Setup(transform, curve);
_mantleStartPosition = GlobalPosition;
var tween = GetTree().CreateTween();
tween.SetTrans(Tween.TransitionType.Linear);
tween.SetEase(Tween.EaseType.InOut);
tween.TweenProperty(_mantlePath.PathFollow, "progress_ratio", 1, MantleTime);
tween.Finished += MantleFinished;
}
public void HandleMantling(float delta)
{
GlobalPosition = _mantlePath.Target.GlobalPosition;
}
public void SimpleDashInDirection(Vector3 direction)
{
SetVelocity(direction * SimpleDashStrength);
}
public void SimpleDash()
{
SimpleDashInDirection(GetInputGlobalHDirection());
}
public void MantleFinished()
{
_mantlePath.Teardown();
var isThereMovementInput = GetMoveInput().Length() > 0;
if (isThereMovementInput)
{
// If there's a movement input on Mantle, we dash in the direction the mantle took place
var positionDifference = GlobalPosition - _mantleStartPosition;
var directionHorizontal = new Vector3(positionDifference.X, 0, positionDifference.Z);
SimpleDashInDirection(directionHorizontal.Normalized());
}
_customMantle = false;
_playerState.SendEvent("grounded");
}
public void HandleJump(float delta, float gravityFactor, int hangFrames)
{
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
// Update horizontal velocity
var horizontalVelocity = ComputeHVelocityAir(delta);
Velocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z);
// Hang time at the top of the jump
if (Velocity.Y <= Mathf.Epsilon)
{
_framesSinceJumpAtApex++;
SetVerticalVelocity(0);
}
// Cancel gravity on jump apex
var gravity = CalculateGravityForce() / gravityFactor;
var isAtApex = _framesSinceJumpAtApex > 0;
if (isAtApex)
{
gravity = 0;
}
// Update velocity accordingly
var newVerticalSpeed = Velocity.Y - gravity * delta;
SetVerticalVelocity(newVerticalSpeed);
if (IsHeadTouchingCeiling())
{
SetVerticalVelocity(Velocity.Y - 2.0f);
}
// Move back to Airborne state management when starting to go down again
if (_framesSinceJumpAtApex > hangFrames)
_playerState.SendEvent("jump_ended");
}
public void HandleSimpleJump(float delta)
{
HandleJump(delta, SimpleJumpGravityLesseningFactor, SimpleJumpHangTimeInFrames);
}
public void HandleDoubleJump(float delta)
{
HandleJump(delta, DoubleJumpGravityLesseningFactor, DoubleJumpHangTimeInFrames);
}
public void HandleMegaJump(float delta)
{
HandleJump(delta, MegaJumpGravityLesseningFactor, MegaJumpHangTimeInFrames);
}
public void PowerRecharging(float delta)
{
var progress = (float) (_powerCooldownTimer.TimeLeft / _powerCooldownTimer.WaitTime);
PowerCooldownIndicator.SetCustomMinimumSize(new Vector2(100 * progress, 10));
}
public void StartPowerCooldown()
{
_powerCooldownTimer.Start();
PowerCooldownIndicator.Visible = true;
}
public void StopPowerCooldown()
{
_powerCooldownTimer.Stop();
PowerCooldownIndicator.Visible = false;
}
public void PowerCooldownExpired()
{
EmpoweredActionsLeft += 1;
var eventToSend = EmpoweredActionsLeft == MaxNumberOfEmpoweredActions ? "fully_charged" : "recharge";
_playerState.SendEvent(eventToSend);
}
///////////////////////////
// Input Management ///////
///////////////////////////
public void OnInputMoveKeyboard(Vector3 value)
{
_inputMoveKeyboard = value;
}
public void OnInputMove(Vector3 value)
{
_inputMove = value;
}
public void OnInputRotateY(float value)
{
_inputRotateY = value;
}
public void OnInputRotateFloorplane(float value)
{
_inputRotateFloorplane = value;
}
public void OnInputAimPressed()
{
_playerState.SendEvent("aim_pressed");
}
public void OnInputAimDown()
{
_playerState.SendEvent("aim_down");
}
public void OnInputAimReleased()
{
_playerState.SendEvent("aim_released");
}
public void OnInputAimCanceled()
{
_playerState.SendEvent("cancel");
DashSystem.StopPreparingDash();
}
public void OnInputHitPressed()
{
if (_aiming.Active)
{
ThrowWeapon();
}
}
public void OnInputEmpowerDown()
{
// _playerState.SendEvent("empower_down");
}
public void OnInputEmpowerReleased()
{
// _playerState.SendEvent("empower_released");
}
public void OnInputDashPressed()
{
if (_aiming.Active && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
_playerState.SendEvent("aimed_dash");
_playerState.SendEvent("cancel_aim");
return;
}
if (_empowerOn.Active && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
_playerState.SendEvent("powered_dash");
return;
}
if (_airborne.Active)
{
if (!_canDashAirborne)
return;
_canDashAirborne = false;
}
_playerState.SendEvent("dash");
}
public void OnAimingEntered()
{
if (!CanPerformEmpoweredAction())
return;
if (WeaponSystem.FlyingState.Active)
{
DashToFlyingWeapon();
return;
}
if (WeaponSystem.PlantedState.Active)
{
DashToPlantedWeapon();
return;
}
DashSystem.StartPreparingDash();
DashIndicatorMesh.Visible = true;
if (!isOnFloorCustom())
ReduceTimeScaleWhileAiming();
}
public void HandleAiming(float delta)
{
RotateWeaponWithPlayer();
DashIndicatorMeshCylinder.Height = DashSystem.PlannedLocation.DistanceTo(GlobalPosition);
DashIndicatorNode.LookAt(DashSystem.PlannedLocation);
if (CanPerformEmpoweredAction())
DashSystem.PrepareDash();
}
public void OnAimingExited()
{
DashSystem.StopPreparingDash();
DashIndicatorMesh.Visible = 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()
{
RecoverWeapon();
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;
_wallHugStartNormal = WeaponSystem.PlantNormal;
_currentWallContactPoint = WeaponSystem.PlantLocation;
_wallHugStartLocation = dashLocation;
_wallHugStartProjectedVelocity = Velocity.Slide(_wallHugStartNormal);
var dashTween = CreatePositionTween(dashLocation, AimedDashTime);
dashTween.Finished += DashToPlantedWeaponTweenEnded;
}
public void RecoverWeapon()
{
RecoverChildNode(WeaponRoot);
WeaponSystem.ResetWeapon();
}
public void DashToPlantedWeaponTweenEnded()
{
// Store the weapon state before resetting it
var isPlantedOnWall = WeaponSystem.IsPlantedInWall();
var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform();
var shouldDashToHanging = isPlantedOnWall || isPlantedUnderPlatform;
RecoverWeapon();
var resultingEvent = shouldDashToHanging ? "dash_to_planted" : "dash_finished";
_playerState.SendEvent(resultingEvent);
}
private Vector3 _preDashVelocity = Vector3.Zero;
public void OnAimedDashStarted()
{
// Adjusting for player height, where the middle of the capsule should get to the dash location instead of the
// feet of the capsule
var correction = DashSystem.CollisionNormal == Vector3.Down ? _playerHeight : DashSystem.DashCastRadius;
var correctedLocation = DashSystem.PlannedLocation + Vector3.Down * correction;
_preDashVelocity = Velocity;
_dashDirection = (correctedLocation - GlobalPosition).Normalized();
var dashTween = CreatePositionTween(correctedLocation, AimedDashTime);
// dashTween.TweenMethod(Callable.From<float>(AimedDashTweenOngoing), 0.0f, 1.0f, AimedDashTime);
dashTween.Finished += AimedDashTweenEnded;
_customMantle = DashSystem.ShouldMantle;
_customMantleCurve = DashSystem.MantleSystem.MantleCurve;
_customMantleStartTransform = DashSystem.MantleSystem.GlobalTransform;
}
Tween CreatePositionTween(Vector3 targetLocation, float tweenTime)
{
var tween = GetTree().CreateTween();
tween.SetParallel();
tween.SetTrans(Tween.TransitionType.Cubic);
tween.SetEase(Tween.EaseType.InOut);
tween.TweenProperty(this, "global_position", targetLocation, tweenTime);
return tween;
}
public void AimedDashTweenEnded()
{
_playerState.SendEvent("dash_finished");
}
public void OnAimedDashFinished()
{
var postDashVelocity = _preDashVelocity.Length() > PostDashSpeed ? PostDashSpeed : _preDashVelocity.Length();
Velocity = _dashDirection * postDashVelocity;
if (_customMantle) _playerState.SendEvent("mantle");
}
public void PlaceWeaponForTutorial()
{
if (TutorialDone)
return;
RemoveChild(WeaponRoot);
GetTree().GetRoot().CallDeferred(Node.MethodName.AddChild, WeaponRoot);
WeaponRoot.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition);
WeaponSystem.CallDeferred(WeaponSystem.MethodName.PlaceWeaponForTutorial, TutorialWeaponTarget.GlobalPosition);
}
public void RemoveChildNode(Node3D node)
{
RemoveChild(node);
GetTree().GetRoot().AddChild(node);
node.SetGlobalPosition(GlobalPosition);
}
public void RecoverChildNode(Node3D node)
{
GetTree().GetRoot().RemoveChild(node);
AddChild(node);
node.SetGlobalPosition(GlobalPosition);
}
public void ThrowWeapon()
{
_playerState.SendEvent("cancel_aim");
RemoveChildNode(WeaponRoot);
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation;
WeaponSystem.ThrowWeapon(
weaponTargetLocation,
DashSystem.HasHit,
DashSystem.CollisionPoint,
DashSystem.CollisionNormal);
}
public void OnSimpleDashStarted()
{
if (!_canDash)
return;
_canDash = false;
SimpleDash();
}
public void HandleSimpleDash(float delta)
{
_playerState.SendEvent("dash_finished");
}
public Vector3 GetInputGlobalHDirection()
{
var direction = Transform.Basis * HeadSystem.Transform.Basis * GetMoveInput();
return new Vector3(direction.X, 0, direction.Z).Normalized();
}
public Vector3 GetInputLocalHDirection()
{
var direction = GetMoveInput();
return new Vector3(direction.X, 0, direction.Z).Normalized();
}
public void OnPoweredDashStarted()
{
Velocity = GetInputGlobalHDirection() * PoweredDashStrength;
GetTree().CreateTimer(PoweredDashTime).Timeout += FinishPoweredDash;
}
public void OnPoweredDashFinished()
{
}
public void FinishPoweredDash()
{
_playerState.SendEvent("dash_finished");
}
public void HandlePoweredDash(float delta)
{
var collision = MoveAndCollide(Velocity * delta, maxCollisions: 10);
if (collision != null)
{
FinishPoweredDash();
}
}
public bool CanPerformEmpoweredAction()
{
return EmpoweredActionsLeft > 0 && TutorialDone;
}
public void PerformEmpoweredAction()
{
_isWallJumpAvailable = true;
EmpoweredActionsLeft--;
_playerState.SendEvent(EmpoweredActionsLeft <= 0 ? "expired" : "power_used");
}
public void StartCoyoteTime()
{
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
}
public void CoyoteExpired()
{
_playerState.SendEvent("coyote_expired");
}
///////////////////////////
// Stateless logic ////////
///////////////////////////
private void LookAround(double delta)
{
Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);
var lookSensitivity = _isUsingGamepad ? _lookSensitivityMultiplier : _mouseSensitivityMultiplier;
var wallHugContactPoint = _onWallRunning.Active || _onWallRunningCoyoteEnabled.Active ? _currentWallContactPoint : Vector3.Zero;
var playerVelocity = GetGlobalMoveInput();
HeadSystem.LookAround(delta, inputLookDir, playerVelocity, wallHugContactPoint, lookSensitivity);
}
public void MoveOnGround(double delta)
{
var horizontalVelocity = ComputeHVelocityGround((float) delta);
Velocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z);
}
public void MoveInAir(double delta)
{
var horizontalVelocity = ComputeHVelocityAir((float) delta);
var verticalVelocity = Velocity.Y - (CalculateGravityForce() * (float)delta);
Velocity = new Vector3(horizontalVelocity.X, verticalVelocity, horizontalVelocity.Z);
}
private void HandleStairs(float delta)
{
StairsSystem.UpStairsCheckParams upStairsCheckParams = new StairsSystem.UpStairsCheckParams
{
IsOnFloorCustom = isOnFloorCustom(),
IsCapsuleHeightLessThanNormal = CapsuleCollider.IsCapsuleHeightLessThanNormal(),
CurrentSpeedGreaterThanWalkSpeed = false,
IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(),
Delta = delta,
FloorMaxAngle = FloorMaxAngle,
GlobalPositionFromDriver = GlobalPosition,
Velocity = Velocity,
GlobalTransformFromDriver = GlobalTransform,
Rid = GetRid()
};
StairsSystem.UpStairsCheckResult upStairsCheckResult = StairsSystem.SnapUpStairsCheck(upStairsCheckParams);
if (upStairsCheckResult.UpdateRequired)
{
upStairsCheckResult.Update(this);
}
else
{
MoveAndSlide();
StairsSystem.DownStairsCheckParams downStairsCheckParams = new StairsSystem.DownStairsCheckParams
{
IsOnFloor = IsOnFloor(),
IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(),
LastFrameWasOnFloor = _lastFrameWasOnFloor,
CapsuleDefaultHeight = CapsuleCollider.GetDefaultHeight(),
CurrentCapsuleHeight = CapsuleCollider.GetCurrentHeight(),
FloorMaxAngle = FloorMaxAngle,
VelocityY = Velocity.Y,
GlobalTransformFromDriver = GlobalTransform,
Rid = GetRid()
};
StairsSystem.DownStairsCheckResult downStairsCheckResult = StairsSystem.SnapDownStairsCheck(
downStairsCheckParams);
if (downStairsCheckResult.UpdateIsRequired)
{
downStairsCheckResult.Update(this);
}
}
StairsSystem.SlideCameraParams slideCameraParams = new StairsSystem.SlideCameraParams
{
IsCapsuleHeightLessThanNormal = CapsuleCollider.IsCapsuleHeightLessThanNormal(),
CurrentSpeedGreaterThanWalkSpeed = false,
BetweenCrouchingAndNormalHeight = CapsuleCollider.IsBetweenCrouchingAndNormalHeight(),
Delta = delta
};
StairsSystem.SlideCameraSmoothBackToOrigin(slideCameraParams);
}
private void CameraModifications(float delta)
{
Bobbing.CameraBobbingParams cameraBobbingParams = new Bobbing.CameraBobbingParams
{
Delta = delta,
IsOnFloorCustom = isOnFloorCustom() || _onWallRunning.Active || _onWallRunningCoyoteEnabled.Active,
Velocity = Velocity,
SettingsMultiplier = _headBobbingMultiplier
};
Bobbing.PerformCameraBobbing(cameraBobbingParams);
FieldOfView.FovParameters fovParams = new FieldOfView.FovParameters
{
IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(),
Delta = delta,
SprintSpeed = WalkSpeed,
Velocity = Velocity,
FOVMultiplier = _fovChangeMultiplier
};
FieldOfView.PerformFovAdjustment(fovParams);
}
///////////////////////////
// Helpers ////////////////
///////////////////////////
public float CalculateGravityForce() => _gravity * Weight;
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++)
{
if (_headCollisionDetectors[i].IsColliding())
{
return true;
}
}
return false;
}
private bool isOnFloorCustom()
{
return IsOnFloor() || StairsSystem.WasSnappedToStairsLastFrame();
}
public void RotateWeaponWithPlayer()
{
WeaponRoot.SetRotation(HeadSystem.Rotation);
}
///////////////////////////
// Processes //////////////
///////////////////////////
public override void _PhysicsProcess(double delta)
{
LookAround(delta);
CameraModifications((float) delta);
HandleStairs((float) delta);
MantleSystem.ProcessMantle(_grounded.Active);
if (WeaponSystem.InHandState.Active)
RotateWeaponWithPlayer();
if (WeaponSystem.InHandState.Active && !_aiming.Active && TutorialDone)
{
DashIndicatorMesh.Visible = false;
}
if (!WeaponSystem.InHandState.Active && TutorialDone)
{
DashIndicatorMesh.Visible = true;
DashIndicatorMeshCylinder.Height = WeaponSystem.GlobalPosition.DistanceTo(GlobalPosition) * 2;
DashIndicatorNode.LookAt(WeaponSystem.GlobalPosition);
}
}
}