fix: less bugs when dashing to planted weapon

This commit is contained in:
2025-06-23 17:10:42 +02:00
parent 4f5ca49c76
commit cf98e6c36c
4 changed files with 14 additions and 24 deletions

View File

@ -265,7 +265,7 @@ delay_in_seconds = "0.0"
[node name="OnDrop" type="Node" parent="StateChart/Root/Actions/Hanging"] [node name="OnDrop" type="Node" parent="StateChart/Root/Actions/Hanging"]
script = ExtResource("28_n7qhm") script = ExtResource("28_n7qhm")
to = NodePath("../../WeaponInHand") to = NodePath("../../WeaponInHand")
event = &"drop" event = &"crouch"
delay_in_seconds = "0.0" delay_in_seconds = "0.0"
[node name="OnMantle" type="Node" parent="StateChart/Root/Actions/Hanging"] [node name="OnMantle" type="Node" parent="StateChart/Root/Actions/Hanging"]

View File

@ -384,9 +384,17 @@ public partial class PlayerController : CharacterBody3D
else if (WeaponSystem.PlantedState.Active) else if (WeaponSystem.PlantedState.Active)
{ {
DashSystem.ShouldMantle = false; DashSystem.ShouldMantle = false;
// Should we try to resolve with mantle? var dashLocation = WeaponSystem.PlantLocation;
var dashLocation = if (WeaponSystem.IsPlantedInWall())
DashSystem.ComputeDashLocationForPlayerShape(WeaponSystem.PlantLocation, WeaponSystem.PlantNormal); {
dashLocation += WeaponSystem.PlantNormal * 0.5f; // Player radius
}
if (WeaponSystem.IsPlantedUnderPlatform())
{
dashLocation += Vector3.Down * 1f; // Player height
}
DashSystem.PlannedPlayerLocation = dashLocation; DashSystem.PlannedPlayerLocation = dashLocation;
} }
_dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized(); _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized();
@ -402,7 +410,6 @@ public partial class PlayerController : CharacterBody3D
return; return;
} }
GD.Print(WeaponSystem.GlobalRotation);
// Store the weapon state before resetting it // Store the weapon state before resetting it
var isPlantedOnWall = WeaponSystem.IsPlantedInWall(); var isPlantedOnWall = WeaponSystem.IsPlantedInWall();
var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform(); var isPlantedUnderPlatform = WeaponSystem.IsPlantedUnderPlatform();

View File

@ -73,24 +73,6 @@ public partial class DashSystem: Node3D
PlannedPlayerLocation = locationAlongPath + CollisionNormal * maxPushDownDistance * proportion * correctionProportion; 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() public void PrepareDash()
{ {
_dashTarget.SetVisible(false); _dashTarget.SetVisible(false);

View File

@ -74,6 +74,7 @@ public partial class WeaponSystem : RigidBody3D
Freeze = true; Freeze = true;
GlobalPosition = PlantLocation; GlobalPosition = PlantLocation;
LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true); LookAt(GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
GD.Print(GlobalRotation);
} }
public void OnThrownWeaponReachesGround(Node other) public void OnThrownWeaponReachesGround(Node other)