gd,fix: fixed a bug where the dash could mantle you nowhere. Automatic mantle at the end of dash.
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
|
||||
public record DashLocation(Result<Vector3, string> Result, bool HasHit);
|
||||
public record DashComputation(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
|
||||
|
||||
public record DashResolve(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
|
||||
|
||||
public partial class DashSystem: Node3D
|
||||
{
|
||||
@ -15,24 +16,35 @@ public partial class DashSystem: Node3D
|
||||
private Camera3D _camera;
|
||||
private MeshInstance3D _dashTarget;
|
||||
|
||||
private MantleSystem _mantleSystem;
|
||||
|
||||
public void Init(Node3D head, Camera3D camera)
|
||||
{
|
||||
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
|
||||
_head = head;
|
||||
_camera = camera;
|
||||
|
||||
_mantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
_mantleSystem.Init(this);
|
||||
|
||||
_dashTarget = GetNode<MeshInstance3D>("DashTarget");
|
||||
_dashTarget.SetVisible(false);
|
||||
}
|
||||
|
||||
private DashLocation ComputeDashLocation()
|
||||
private DashComputation ComputeDashLocation()
|
||||
{
|
||||
var dashLocation = _dashCast3D.IsColliding()
|
||||
? _dashCast3D.GetCollisionPoint(0)
|
||||
: _dashCast3D.ToGlobal(_dashCast3D.TargetPosition);
|
||||
return new DashLocation(Result.Ok(dashLocation), _dashCast3D.IsColliding());
|
||||
if (!_dashCast3D.IsColliding())
|
||||
{
|
||||
return new DashComputation(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero);
|
||||
}
|
||||
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
|
||||
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
|
||||
var collisionShape = (SphereShape3D) _dashCast3D.GetShape();
|
||||
var centerSphereLocation = collisionPoint + collisionNormal * collisionShape.Radius;
|
||||
return new DashComputation(true, centerSphereLocation, collisionPoint, collisionNormal);
|
||||
}
|
||||
|
||||
public Result<Vector3, string> PrepareDash()
|
||||
public DashResolve PrepareDash()
|
||||
{
|
||||
_dashTarget.SetVisible(false);
|
||||
|
||||
@ -41,16 +53,23 @@ public partial class DashSystem: Node3D
|
||||
_head.Rotation.Y,
|
||||
_camera.Rotation.Z));
|
||||
|
||||
var (result, hasHit) = ComputeDashLocation();
|
||||
var (hasHit, location, collisionPoint, collisionNormal) = ComputeDashLocation();
|
||||
|
||||
var shouldMantle = false;
|
||||
var mantleLocation = Vector3.Zero;
|
||||
if (hasHit && Mathf.Abs(collisionNormal.Y) < 0.01f)
|
||||
{
|
||||
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(collisionPoint, collisionNormal);
|
||||
shouldMantle = mantleResult.IsSome(out mantleLocation);
|
||||
}
|
||||
|
||||
var targetColor = hasHit ? new Color(0.2f, 0.2f, 1f) : new Color(1f, 1f, 1f);
|
||||
var targetColor = shouldMantle ? new Color(0.2f, 0.2f, 1f) : new Color(1f, 1f, 1f);
|
||||
var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0);
|
||||
targetMaterial.AlbedoColor = targetColor;
|
||||
|
||||
targetMaterial.SetAlbedo(targetColor);
|
||||
_dashTarget.SetVisible(true);
|
||||
_dashTarget.SetGlobalPosition(result.Unwrap());
|
||||
_dashTarget.SetGlobalPosition(location);
|
||||
|
||||
return result;
|
||||
return new DashResolve(shouldMantle, location, mantleLocation);
|
||||
}
|
||||
|
||||
public void Dash()
|
||||
|
Reference in New Issue
Block a user