mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 10:25:54 +00:00
Crosshair
This commit is contained in:
parent
e5a60a6ccd
commit
fe552608ee
13 changed files with 264 additions and 33 deletions
70
Scripts/Components/Actors/3D/PlayerCrosshairModule3D.cs
Normal file
70
Scripts/Components/Actors/3D/PlayerCrosshairModule3D.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors._3D;
|
||||
|
||||
public partial class PlayerCrosshairModule3D : ModuleBase<PlayerState, CharacterBody3D>
|
||||
{
|
||||
[Export] public IsoPlayerStorageModule Storage { get; set; }
|
||||
[Export]
|
||||
public AnimatedSprite3D AnimatedSprite { get; private set; }
|
||||
|
||||
[Export]
|
||||
public float CrosshairDistance { get; private set; }
|
||||
|
||||
public bool Enabled { get; set; } = false;
|
||||
|
||||
private IStateMachine<PlayerState, CharacterBody3D> _machine;
|
||||
|
||||
public void UpdatePosition(Vector2 facingDirection)
|
||||
{
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(facingDirection);
|
||||
}
|
||||
|
||||
private Vector3 CalculateCrosshairPosition(Vector2 facingDirection)
|
||||
{
|
||||
var pos2d = facingDirection * CrosshairDistance;
|
||||
|
||||
var pos3d = pos2d.ToVector3(0);
|
||||
|
||||
return pos3d;
|
||||
}
|
||||
|
||||
public override void EnterState(PlayerState state)
|
||||
{
|
||||
Enabled = true;
|
||||
AnimatedSprite.Show();
|
||||
}
|
||||
|
||||
public override void ExitState(PlayerState state)
|
||||
{
|
||||
Enabled = false;
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
_machine = machine;
|
||||
AnimatedSprite.Hide();
|
||||
}
|
||||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
AnimatedSprite.Position = CalculateCrosshairPosition(Storage.FacingDirection);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue