mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Rudimentary mouse aiming
This commit is contained in:
parent
dffbf55d2d
commit
4d9d566b2f
1 changed files with 28 additions and 1 deletions
|
|
@ -34,6 +34,9 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
[Export] private StringName _inventoryActionName = "inventory";
|
||||
[Export] private StringName _pauseActionName = "pause";
|
||||
|
||||
private enum AimInputMethod { RightStick, Mouse }
|
||||
private AimInputMethod _lastUsedInput = AimInputMethod.RightStick;
|
||||
|
||||
public override Vector2 GetMovementInput()
|
||||
{
|
||||
return Input.GetVector(LeftAxisName, RightAxisName, UpAxisName, DownAxisName);
|
||||
|
|
@ -41,7 +44,20 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
|
||||
public override Vector2 GetAimInput()
|
||||
{
|
||||
return GetRightStickInput();
|
||||
Vector2 rightStickInput = GetRightStickInput();
|
||||
Vector2 mouseInput = GetMouseAimInput();
|
||||
|
||||
// Determine which input method to use
|
||||
if (rightStickInput != Vector2.Zero)
|
||||
{
|
||||
_lastUsedInput = AimInputMethod.RightStick;
|
||||
}
|
||||
else if (mouseInput != Vector2.Zero)
|
||||
{
|
||||
_lastUsedInput = AimInputMethod.Mouse;
|
||||
}
|
||||
|
||||
return _lastUsedInput == AimInputMethod.RightStick ? rightStickInput : mouseInput;
|
||||
}
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
|
|
@ -51,6 +67,17 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
Input.GetAxis(UpAimName, DownAimName)
|
||||
);
|
||||
}
|
||||
|
||||
private Vector2 GetMouseAimInput()
|
||||
{
|
||||
//Camera2D camera = GetViewport().GetCamera2D();
|
||||
//if (camera == null) return Vector2.Zero; // Ensure there's a valid camera
|
||||
|
||||
//Vector2 mouseScreenPos = GetViewport().get_local_mouse_position();
|
||||
Vector2 mouseWorldPos = this.GetGlobalMousePosition();
|
||||
|
||||
return mouseWorldPos - this.GlobalPosition; // Get direction vector
|
||||
}
|
||||
|
||||
public override bool GetActionJustPressed(string action)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue