gd: dash target
This commit is contained in:
35
player_controller/Scripts/DashSystem.cs
Normal file
35
player_controller/Scripts/DashSystem.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
|
||||
public partial class DashSystem: Node3D
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
||||
public float DashSpeed { get; set; } = 0.05f;
|
||||
|
||||
private Node3D _head;
|
||||
private ShapeCast3D _dashCast3D;
|
||||
private Camera3D _camera;
|
||||
|
||||
public void Init(Node3D head, Camera3D camera)
|
||||
{
|
||||
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
|
||||
_head = head;
|
||||
_camera = camera;
|
||||
}
|
||||
|
||||
public Result<Vector3, string> PrepareDash()
|
||||
{
|
||||
_dashCast3D.SetRotation(new Vector3(
|
||||
_camera.Rotation.X,
|
||||
_head.Rotation.Y,
|
||||
_camera.Rotation.Z));
|
||||
|
||||
var dashLocation = _dashCast3D.IsColliding()
|
||||
? _dashCast3D.GetCollisionPoint(0)
|
||||
: _dashCast3D.GetTargetPosition();
|
||||
|
||||
return Result.Ok(dashLocation);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user