From cf98e6c36c062927407e0708906f4dced58bf8c5 Mon Sep 17 00:00:00 2001 From: Minimata Date: Mon, 23 Jun 2025 17:10:42 +0200 Subject: [PATCH] fix: less bugs when dashing to planted weapon --- player_controller/PlayerController.tscn | 2 +- player_controller/Scripts/PlayerController.cs | 15 ++++++++++---- systems/dash/DashSystem.cs | 20 +------------------ systems/weapon/WeaponSystem.cs | 1 + 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 348f6ed..9e8e39f 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -265,7 +265,7 @@ delay_in_seconds = "0.0" [node name="OnDrop" type="Node" parent="StateChart/Root/Actions/Hanging"] script = ExtResource("28_n7qhm") to = NodePath("../../WeaponInHand") -event = &"drop" +event = &"crouch" delay_in_seconds = "0.0" [node name="OnMantle" type="Node" parent="StateChart/Root/Actions/Hanging"] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index b63962e..ceb832b 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -384,9 +384,17 @@ public partial class PlayerController : CharacterBody3D else if (WeaponSystem.PlantedState.Active) { DashSystem.ShouldMantle = false; - // Should we try to resolve with mantle? - var dashLocation = - DashSystem.ComputeDashLocationForPlayerShape(WeaponSystem.PlantLocation, WeaponSystem.PlantNormal); + 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(); @@ -402,7 +410,6 @@ public partial class PlayerController : CharacterBody3D return; } - GD.Print(WeaponSystem.GlobalRotation); // Store the weapon state before resetting it var isPlantedOnWall = WeaponSystem.IsPlantedInWall(); var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform(); diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index d7c580b..bdbf1e1 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -68,29 +68,11 @@ public partial class DashSystem: Node3D var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction; var maxPushDownDistance = 0.9f; - var correctionProportion = (float)Mathf.Remap(CollisionNormal.Y, -0.5, -1, 0, 1); + var correctionProportion = (float) Mathf.Remap(CollisionNormal.Y, -0.5, -1, 0, 1); var proportion = (float) Mathf.Remap(_dashCast3D.GlobalRotation.X, 0, 1.57, 0, 1); PlannedPlayerLocation = locationAlongPath + CollisionNormal * maxPushDownDistance * proportion * correctionProportion; } - public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null) - { - if (!normal.HasValue) - return location; - - var castStartLocation = location + 2 * normal.Value; - var castEndLocation = -2 * normal.Value; - _playerCast3D.SetGlobalPosition(castStartLocation); - _playerCast3D.SetTargetPosition(castEndLocation); - - if (!_playerCast3D.IsColliding()) - return castEndLocation; - - var fraction = _playerCast3D.GetClosestCollisionSafeFraction(); - var locationAlongPath = castEndLocation * fraction; - return castStartLocation + locationAlongPath; - } - public void PrepareDash() { _dashTarget.SetVisible(false); diff --git a/systems/weapon/WeaponSystem.cs b/systems/weapon/WeaponSystem.cs index 9a995a0..0678fba 100644 --- a/systems/weapon/WeaponSystem.cs +++ b/systems/weapon/WeaponSystem.cs @@ -74,6 +74,7 @@ public partial class WeaponSystem : RigidBody3D Freeze = true; GlobalPosition = PlantLocation; LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true); + GD.Print(GlobalRotation); } public void OnThrownWeaponReachesGround(Node other)