From 7b036c588985d4fd7bc9488b40bc448db06fc09c Mon Sep 17 00:00:00 2001 From: Minimata Date: Tue, 16 Sep 2025 10:28:41 +0200 Subject: [PATCH] fixed mantle after dash bug --- player_controller/PlayerController.tscn | 1 + player_controller/Scripts/PlayerController.cs | 8 +++--- systems/dash/DashSystem.cs | 5 ++-- systems/dash/dash_system.tscn | 2 +- systems/mantle/MantleSystem.cs | 26 ++++++------------- systems/move/MoveSystem.cs | 18 ------------- 6 files changed, 17 insertions(+), 43 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index eef81cc8..0d5878ac 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -53,6 +53,7 @@ WalkSpeed = 7.5 AccelerationAir = 2.0 DecelerationAir = 0.1 Weight = 5.0 +MantleTime = 0.2 SimpleJumpStartVelocity = 8.0 SimpleJumpHangTimeInFrames = 1 SimpleJumpGravityLesseningFactor = 2.5 diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 54eec46f..ca0f8fe0 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -310,7 +310,7 @@ public partial class PlayerController : CharacterBody3D // Movement stuff // Getting universal setting from GODOT editor to be in sync _gravity = (float)ProjectSettings.GetSetting("physics/3d/default_gravity"); - MantleSystem.Init(HeadSystem); + MantleSystem.Init(); StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth); DashSystem.Init(HeadSystem, camera, TweenQueueSystem); WeaponSystem.Init(HeadSystem, camera); @@ -438,7 +438,7 @@ public partial class PlayerController : CharacterBody3D { if (CanMantle()) { - MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap()); + MantleToLocation(MantleSystem.FindMantleForHeadRotation(HeadSystem.Rotation.Y).Unwrap()); return; } @@ -871,7 +871,7 @@ public partial class PlayerController : CharacterBody3D { // Try mantling but don't know if this is useful if (CanMantle()) - MantleToLocation(MantleSystem.FindMantleInFrontOfPlayer().Unwrap()); + MantleToLocation(MantleSystem.FindMantleForHeadRotation(HeadSystem.Rotation.Y).Unwrap()); } public void FinishPoweredDash() @@ -912,7 +912,7 @@ public partial class PlayerController : CharacterBody3D // Mantling public bool CanMantle() { - var mantleLocationResult = MantleSystem.FindMantleInFrontOfPlayer(); + var mantleLocationResult = MantleSystem.FindMantleForHeadRotation(HeadSystem.Rotation.Y); return mantleLocationResult.IsSome(out _); } public void MantleToLocation(Vector3 location) diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index 7ba6cba6..31f7dbd7 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -66,7 +66,7 @@ public partial class DashSystem: Node3D _tweenQueueSystem = tweenQueueSystem; _mantleSystem = GetNode("MantleSystem"); - _mantleSystem.Init(this); + _mantleSystem.Init(); _dashTarget = GetNode("DashTarget"); _dashTarget.SetVisible(false); @@ -116,7 +116,8 @@ public partial class DashSystem: Node3D var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0); targetMaterial.SetAlbedo(targetColor); _dashTarget.SetVisible(true); - _dashTarget.SetGlobalPosition(PlannedLocation); + var targetLocation = ShouldMantle ? PlannedMantleLocation : PlannedLocation; + _dashTarget.SetGlobalPosition(targetLocation); } public void StopPreparingDash() diff --git a/systems/dash/dash_system.tscn b/systems/dash/dash_system.tscn index fe401ec9..273d4a49 100644 --- a/systems/dash/dash_system.tscn +++ b/systems/dash/dash_system.tscn @@ -35,7 +35,7 @@ mesh = SubResource("SphereMesh_qu4wy") surface_material_override/0 = SubResource("StandardMaterial3D_v31n3") [node name="MantleSystem" parent="." instance=ExtResource("2_pff7b")] -MantleEndLocationDistanceFromWall = 0.3 +MantleEndLocationDistanceFromWall = 0.25 MantleHeightCastStart = 2.0 [node name="DashIndicator" parent="." instance=ExtResource("2_tqt6i")] diff --git a/systems/mantle/MantleSystem.cs b/systems/mantle/MantleSystem.cs index f72703cf..2c34fe5a 100644 --- a/systems/mantle/MantleSystem.cs +++ b/systems/mantle/MantleSystem.cs @@ -5,50 +5,40 @@ namespace Movementtests.systems; public partial class MantleSystem: Node3D { - [Export(PropertyHint.Range, "0,2,0.1,suffix:m,or_greater")] + [Export(PropertyHint.Range, "0,2,0.01,suffix:m,or_greater")] public float MantleEndLocationDistanceFromWall { get; set; } = 1f; [Export(PropertyHint.Range, "0,10,0.1,suffix:m,or_greater")] public float MantleHeightCastStart { get; set; } = 2f; [Export(PropertyHint.Range, "0,10,0.01,suffix:m,or_greater")] public float MaxStepHeight = 0.5f; - private Node3D _head; private ShapeCast3D _wallInFrontCast3D; private ShapeCast3D _mantleCast3D; private RayCast3D _mantleCheckCast3D; private Option _mantleLocation; - public void Init(Node3D head) + public void Init() { - _head = head; _wallInFrontCast3D = GetNode("WallInFrontCast3D"); _mantleCast3D = GetNode("MantleCast3D"); } - public override void _PhysicsProcess(double delta) + public Option FindMantleForHeadRotation(float rotation) { - base._PhysicsProcess(delta); - _wallInFrontCast3D.SetRotation(new Vector3( _wallInFrontCast3D.Rotation.X, - _head.Rotation.Y, + rotation, _wallInFrontCast3D.Rotation.Z)); if (!_wallInFrontCast3D.IsColliding()) { - _mantleLocation = Option.None; - return; + return Option.None; } var collisionPoint = _wallInFrontCast3D.GetCollisionPoint(0); var collisionNormal = _wallInFrontCast3D.GetCollisionNormal(0); - _mantleLocation = FindMantleLocationAtPoint(collisionPoint, collisionNormal); - } - - public Option FindMantleInFrontOfPlayer() - { - return _mantleLocation; + return FindMantleLocationAtPoint(collisionPoint, collisionNormal); } public Option FindMantleLocationAtPoint(Vector3 point, Vector3 wallNormal) @@ -59,8 +49,8 @@ public partial class MantleSystem: Node3D _mantleCast3D.SetGlobalPosition(shapeCastStartLocation); var targetLocation = Vector3.Down * MantleHeightCastStart + Vector3.Up * MaxStepHeight; _mantleCast3D.SetTargetPosition(targetLocation); - - if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y > 0.9f) + + if (_mantleCast3D.IsColliding() && _mantleCast3D.GetCollisionNormal(0).Y >= 0.1f) return Option.Some(_mantleCast3D.GetCollisionPoint(0)); return Option.None; } diff --git a/systems/move/MoveSystem.cs b/systems/move/MoveSystem.cs index 9fd0e0b0..084a6634 100644 --- a/systems/move/MoveSystem.cs +++ b/systems/move/MoveSystem.cs @@ -218,22 +218,4 @@ public partial class MoveSystem : Node3D var jumpVelocity = jumpForce * effectiveJumpDirection * boost; _parent.Velocity = currentHorizontalVelocity + jumpVelocity; } - - public bool CanMantle() - { - var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer(); - return mantleLocationResult.IsSome(out _); - } - - public Option Mantle() - { - var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer(); - if (mantleLocationResult.IsSome(out var mantleLocation)) - { - var duration = 0.1f * mantleLocation.DistanceTo(_parent.Position); - var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(mantleLocation, duration)); - return tween.Some(); - } - return Option.None; - } } \ No newline at end of file