aim dashing through targetable entities now possible

This commit is contained in:
2026-01-24 13:49:16 +01:00
parent 4d419b9010
commit b84b7e4dd5
6 changed files with 80 additions and 41 deletions

View File

@@ -1,10 +1,11 @@
using Godot;
using Movementtests.interfaces;
namespace Movementtests.systems;
public partial class DashSystem: Node3D
{
public record DashLocation(bool HasHit, Vector3 TargetLocation, Vector3 CollisionPoint, Vector3 CollisionNormal);
public record DashLocation(bool HasHit, Vector3 TargetLocation, Vector3 CollisionPoint, Vector3 CollisionNormal, GodotObject HitObject = null);
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
@@ -13,9 +14,11 @@ public partial class DashSystem: Node3D
public float PostDashSpeed { get; set; } = 0f;
public bool HasHit { get; set; }
public bool CanDashThroughTarget { get; set; }
public Vector3 TargetLocation { get; set; }
public Vector3 CollisionPoint { get; set; }
public Vector3 CollisionNormal { get; set; }
public GodotObject CollidedObject { get; set; }
public Vector3 PlannedLocation { get; set; }
public bool ShouldMantle { get; set; }
@@ -84,21 +87,27 @@ public partial class DashSystem: Node3D
var collisionPoint = DashCast3D.GetCollisionPoint(0);
var collisionNormal = DashCast3D.GetCollisionNormal(0);
var collidedObject = DashCast3D.GetCollider(0);
var fraction = DashCast3D.GetClosestCollisionSafeFraction();
var globalSweepPath = targetLocation - DashCast3D.GlobalPosition;
var locationAlongPath = DashCast3D.GlobalPosition + globalSweepPath * fraction;
return new DashLocation(true, locationAlongPath, collisionPoint, collisionNormal);
return new DashLocation(true, locationAlongPath, collisionPoint, collisionNormal, collidedObject);
}
public void PrepareDash()
{
DashCast3D.SetRotation(_head.GetGlobalLookRotation());
(HasHit, PlannedLocation, CollisionPoint, CollisionNormal) = ComputeDashLocation();
(HasHit, PlannedLocation, CollisionPoint, CollisionNormal, CollidedObject) = ComputeDashLocation();
CanDashThroughTarget = false;
if (CollidedObject is ITargetable targetable)
{
_dashTarget.SetVisible(false);
CanDashThroughTarget = true;
return;
}
// TODO: Position mantle system to planned location, aligned with ground planned and facing the same way as the dash
// Then query it being careful when dashing underneath a platform and such
MantleSystem.SetGlobalPosition(PlannedLocation);
MantleSystem.SetRotation(new Vector3(
MantleSystem.Rotation.X,
@@ -115,6 +124,7 @@ public partial class DashSystem: Node3D
_dashTarget.SetVisible(true);
var targetLocation = ShouldMantle ? MantleSystem.FirstMantleProfilePoint : PlannedLocation;
_dashTarget.SetGlobalPosition(targetLocation);
return;
var shouldShowDropIndicator = !HasHit && !ShouldMantle;
_dashDropIndicator.SetVisible(shouldShowDropIndicator);
@@ -141,13 +151,9 @@ public partial class DashSystem: Node3D
public void StopPreparingDash()
{
CanDashThroughTarget = false;
_dashTarget.SetVisible(false);
_dashDropIndicator.SetVisible(false);
_dashDropLocationIndicator.SetVisible(false);
}
public void StartPreparingDash()
{
_dashTarget.SetVisible(true);
}
}