fix: fixed some dash issues, there's still some

This commit is contained in:
2025-06-20 13:56:42 +02:00
parent 3a761fd0bd
commit 4f5ca49c76
2 changed files with 49 additions and 45 deletions

View File

@ -233,7 +233,6 @@ public partial class PlayerController : CharacterBody3D
public void OnInputAimPressed() public void OnInputAimPressed()
{ {
GD.Print("InputAimPressed");
_playerState.SendEvent("aim_pressed"); _playerState.SendEvent("aim_pressed");
} }
public void OnInputAimDown() public void OnInputAimDown()
@ -379,16 +378,18 @@ public partial class PlayerController : CharacterBody3D
_timeAfterDashingTimer.Start(); _timeAfterDashingTimer.Start();
if (WeaponSystem.FlyingState.Active) if (WeaponSystem.FlyingState.Active)
{ {
DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero); DashSystem.ShouldMantle = false;
DashSystem.PlannedPlayerLocation = WeaponSystem.GlobalPosition;
} }
else if (WeaponSystem.PlantedState.Active) else if (WeaponSystem.PlantedState.Active)
{ {
DashSystem.ShouldMantle = false;
// Should we try to resolve with mantle? // Should we try to resolve with mantle?
var dashLocation = var dashLocation =
DashSystem.ComputeDashLocationForPlayerShape(WeaponSystem.PlantLocation, WeaponSystem.PlantNormal); DashSystem.ComputeDashLocationForPlayerShape(WeaponSystem.PlantLocation, WeaponSystem.PlantNormal);
DashSystem.DashResolve = new DashResolveRecord(false, dashLocation, Vector3.Zero); DashSystem.PlannedPlayerLocation = dashLocation;
} }
_dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized(); _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized();
DashSystem.Dash(); DashSystem.Dash();
} }
public void OnDashEnded() public void OnDashEnded()
@ -436,12 +437,15 @@ public partial class PlayerController : CharacterBody3D
RemoveChild(WeaponRoot); RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot); GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition); WeaponRoot.SetGlobalPosition(GlobalPosition);
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
DashSystem.CancelDash(); DashSystem.CancelDash();
WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal);
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation;
WeaponSystem.ThrowWeapon(
weaponTargetLocation,
DashSystem.HasHit,
DashSystem.CollisionPoint,
DashSystem.CollisionNormal);
} }
public void OnAimingEntered() public void OnAimingEntered()
{ {

View File

@ -2,10 +2,6 @@
namespace Movementtests.systems; namespace Movementtests.systems;
public record DashComputationRecord(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
public record DashResolveRecord(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
public partial class DashSystem: Node3D public partial class DashSystem: Node3D
{ {
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")] [Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
@ -13,6 +9,15 @@ public partial class DashSystem: Node3D
[Export(PropertyHint.Range, "0,1000,1,or_greater")] [Export(PropertyHint.Range, "0,1000,1,or_greater")]
public float PostDashSpeed { get; set; } = 0f; public float PostDashSpeed { get; set; } = 0f;
public bool HasHit { get; set; }
public Vector3 TargetLocation { get; set; }
public Vector3 CollisionPoint { get; set; }
public Vector3 CollisionNormal { get; set; }
public Vector3 PlannedPlayerLocation { get; set; }
public bool ShouldMantle { get; set; }
public Vector3 PlannedMantleLocation { get; set; }
private Node3D _head; private Node3D _head;
private ShapeCast3D _dashCast3D; private ShapeCast3D _dashCast3D;
private ShapeCast3D _playerCast3D; private ShapeCast3D _playerCast3D;
@ -23,9 +28,6 @@ public partial class DashSystem: Node3D
private MantleSystem _mantleSystem; private MantleSystem _mantleSystem;
private MeshInstance3D _dashTarget; private MeshInstance3D _dashTarget;
public DashResolveRecord DashResolve { get; set; }
public DashComputationRecord DashComputation { get; set; }
[Signal] [Signal]
public delegate void DashStartedEventHandler(); public delegate void DashStartedEventHandler();
@ -48,27 +50,27 @@ public partial class DashSystem: Node3D
_dashTarget.SetVisible(false); _dashTarget.SetVisible(false);
} }
private DashComputationRecord ComputeDashLocation() private void ComputeDashLocation()
{ {
if (!_dashCast3D.IsColliding()) TargetLocation = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition);
HasHit = _dashCast3D.IsColliding();
if (!HasHit)
{ {
return new DashComputationRecord(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero); PlannedPlayerLocation = TargetLocation;
return;
} }
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
var collisionNormal = _dashCast3D.GetCollisionNormal(0); CollisionPoint = _dashCast3D.GetCollisionPoint(0);
// var playerEndLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal); CollisionNormal = _dashCast3D.GetCollisionNormal(0);
var fraction = _dashCast3D.GetClosestCollisionSafeFraction(); var fraction = _dashCast3D.GetClosestCollisionSafeFraction();
var globalSweepPath = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition) - _dashCast3D.GlobalPosition; var globalSweepPath = TargetLocation - _dashCast3D.GlobalPosition;
var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction; var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction;
var maxPushDownDistance = 0.9f; 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); var proportion = (float) Mathf.Remap(_dashCast3D.GlobalRotation.X, 0, 1.57, 0, 1);
locationAlongPath += collisionNormal * maxPushDownDistance * proportion * correctionProportion; PlannedPlayerLocation = locationAlongPath + CollisionNormal * maxPushDownDistance * proportion * correctionProportion;
var otherLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal);
return new DashComputationRecord(true, locationAlongPath, collisionPoint, collisionNormal);
} }
public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null) public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null)
@ -98,26 +100,24 @@ public partial class DashSystem: Node3D
_head.Rotation.Y, _head.Rotation.Y,
_camera.Rotation.Z)); _camera.Rotation.Z));
DashComputation = ComputeDashLocation(); ComputeDashLocation();
var (hasHit, location, collisionPoint, collisionNormal) = DashComputation;
var shouldMantle = false;
var mantleLocation = Vector3.Zero;
if (hasHit && Mathf.Abs(collisionNormal.Y) < 0.5f)
{
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(collisionPoint, collisionNormal);
shouldMantle = mantleResult.IsSome(out mantleLocation);
}
var targetColor = hasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f); ShouldMantle = false;
targetColor = shouldMantle ? new Color(0.2f, 0.2f, 1f) : targetColor; var mantleLocation = Vector3.Zero;
if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f)
{
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(CollisionPoint, CollisionNormal);
ShouldMantle = mantleResult.IsSome(out mantleLocation);
}
PlannedMantleLocation = mantleLocation;
var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f);
targetColor = ShouldMantle ? new Color(0.2f, 0.2f, 1f) : targetColor;
var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0); var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0);
targetMaterial.SetAlbedo(targetColor); targetMaterial.SetAlbedo(targetColor);
_dashTarget.SetVisible(true); _dashTarget.SetVisible(true);
_dashTarget.SetGlobalPosition(location); _dashTarget.SetGlobalPosition(PlannedPlayerLocation);
DashResolve = new DashResolveRecord(shouldMantle, location, mantleLocation);
} }
public void CancelDash() public void CancelDash()
@ -134,12 +134,12 @@ public partial class DashSystem: Node3D
{ {
EmitSignal(SignalName.DashStarted); EmitSignal(SignalName.DashStarted);
_dashTarget.SetVisible(false); _dashTarget.SetVisible(false);
var dashTweenInputs = new TweenQueueSystem.TweenInputs(DashResolve.DashLocation, 0.1f); var dashTweenInputs = new TweenQueueSystem.TweenInputs(PlannedPlayerLocation, 0.1f);
var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs); var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs);
dashTween.Finished += DashTweenEnded; dashTween.Finished += DashTweenEnded;
if (DashResolve.EndWithMantle) if (ShouldMantle)
{ {
_tweenQueueSystem.QueueTween(DashResolve.MantleLocation, 0.2f); _tweenQueueSystem.QueueTween(PlannedMantleLocation, 0.2f);
} }
} }