mantle system fix amazing
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 22s
Create tag and build when new code gets to main / Export (push) Successful in 8m19s

This commit is contained in:
2025-12-19 18:59:34 +01:00
parent 2e2df4ff50
commit b792e8721c
8 changed files with 156 additions and 76 deletions

View File

@@ -81,6 +81,8 @@ public partial class PlayerController : CharacterBody3D
[ExportGroup("Mantle")]
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float MantleTime { get; set; } = 0.1f;
[Export]
public PackedScene MantlePath { get; set; } = GD.Load<PackedScene>("res://scenes/path/Path.tscn");
// Jump
[ExportGroup("Jump")]
@@ -186,6 +188,11 @@ public partial class PlayerController : CharacterBody3D
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;
@@ -197,7 +204,7 @@ public partial class PlayerController : CharacterBody3D
private StateChartState _grounded;
private StateChartState _airborne;
private StateChartState _coyoteEnabled;
private StateChartState _doubleJumpEnabled;
// private StateChartState _doubleJumpEnabled;
private StateChartState _simpleJump;
private StateChartState _doubleJump;
private StateChartState _megaJump;
@@ -221,6 +228,7 @@ public partial class PlayerController : CharacterBody3D
private float _playerHeight;
private float _playerRadius;
private bool _isJumpInputPressed = false;
private float _lookSensitivityMultiplier = 1.0f;
private float _mouseSensitivityMultiplier = 1.0f;
@@ -294,7 +302,7 @@ public partial class PlayerController : CharacterBody3D
_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"));
// _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"));
@@ -351,6 +359,7 @@ public partial class PlayerController : CharacterBody3D
_grounded.StateEntered += OnGrounded;
_grounded.StatePhysicsProcessing += HandleGrounded;
_airborne.StatePhysicsProcessing += HandleAirborne;
_onWall.StatePhysicsProcessing += HandleOnWall;
_coyoteEnabled.StateEntered += StartCoyoteTime;
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
@@ -454,20 +463,29 @@ public partial class PlayerController : CharacterBody3D
{
_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())
return;
@@ -497,6 +515,11 @@ public partial class PlayerController : CharacterBody3D
}
}
public void HandleOnWall(float delta)
{
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
}
public void OnWallHuggingStarted()
{
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
@@ -507,11 +530,6 @@ public partial class PlayerController : CharacterBody3D
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
}
private Vector3 _wallHugStartLocation = Vector3.Zero;
private Vector3 _wallHugStartNormal = Vector3.Zero;
private Vector3 _wallHugStartProjectedVelocity = Vector3.Zero;
private Vector3 _currentWallContactPoint = Vector3.Zero;
public void OnWallDetected()
{
FinishPoweredDash();
@@ -591,10 +609,11 @@ public partial class PlayerController : CharacterBody3D
Velocity = Vector3.Zero;
GlobalPosition = _wallHugStartLocation;
}
// Jump
public void OnInputJumpStarted()
{
_isJumpInputPressed = true;
if (MantleSystem.IsMantlePossible)
{
_playerState.SendEvent("mantle");
@@ -620,6 +639,7 @@ public partial class PlayerController : CharacterBody3D
public void OnInputJumpEnded()
{
_isJumpInputPressed = false;
_playerState.SendEvent("jump_ended");
}
@@ -725,38 +745,48 @@ public partial class PlayerController : CharacterBody3D
z: velocity.Y);
}
private Path _mantlePath;
public void OnMantleStarted()
{
HeadSystem.OnMantle();
_mantlePath = MantlePath.Instantiate() as Path;
if (_mantlePath == null)
{
GD.PrintErr("Failed to instantiate MantlePath");
return;
};
_preMantleVelocity = Velocity;
GetTree().GetRoot().AddChild(_mantlePath);
_mantlePath.Setup(MantleSystem.GlobalTransform, MantleSystem.MantleCurve);
var tween = GetTree().CreateTween();
tween.SetTrans(Tween.TransitionType.Cubic);
tween.SetTrans(Tween.TransitionType.Linear);
tween.SetEase(Tween.EaseType.InOut);
var inbetweenDuration = MantleTime / MantleSystem.NumberOfValidPofiles;
for (int i = 0; i < MantleSystem.NumberOfValidPofiles; i += 1)
{
var position = MantleSystem.WallProfilePositions[i];
tween.TweenProperty(this, "global_position", position, inbetweenDuration);
}
tween.TweenProperty(_mantlePath.PathFollow, "progress_ratio", 1, MantleTime);
tween.Finished += MantleFinished;
}
public void HandleMantling(float delta)
{
GlobalPosition = _mantlePath.Target.GlobalPosition;
}
public void MantleFinished()
{
Velocity = _preMantleVelocity;
_mantlePath.Teardown();
var direction = GetInputGlobalHDirection();
if (direction.Length() > 0)
{
SetVelocity(direction * SimpleDashStrength);
}
_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);
@@ -986,9 +1016,7 @@ public partial class PlayerController : CharacterBody3D
public void RecoverWeapon()
{
GetTree().GetRoot().RemoveChild(WeaponRoot);
AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
RecoverChildNode(WeaponRoot);
WeaponSystem.ResetWeapon();
}
@@ -1051,14 +1079,25 @@ public partial class PlayerController : CharacterBody3D
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");
RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
RemoveChildNode(WeaponRoot);
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation;
WeaponSystem.ThrowWeapon(