mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-05 17:21:17 +00:00
3D Aiming
This commit is contained in:
parent
341f76d885
commit
595bdcc501
3 changed files with 24 additions and 4 deletions
|
|
@ -123,6 +123,7 @@ public partial class KeyboardInputProvider : InputProvider
|
||||||
|
|
||||||
private Vector2 GetMouseAimInput()
|
private Vector2 GetMouseAimInput()
|
||||||
{
|
{
|
||||||
|
|
||||||
return _mouseAImProvider?.GetMouseAimInput() ?? Vector2.Zero;
|
return _mouseAImProvider?.GetMouseAimInput() ?? Vector2.Zero;
|
||||||
// //Camera2D camera = GetViewport().GetCamera2D();
|
// //Camera2D camera = GetViewport().GetCamera2D();
|
||||||
// //if (camera == null) return Vector2.Zero; // Ensure there's a valid camera
|
// //if (camera == null) return Vector2.Zero; // Ensure there's a valid camera
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,32 @@ namespace Cirno.Scripts.Components.Actors;
|
||||||
|
|
||||||
public partial class MouseAimProvider3D : Node3D, IMouseAimProvider
|
public partial class MouseAimProvider3D : Node3D, IMouseAimProvider
|
||||||
{
|
{
|
||||||
public Vector2 GetMouseAimInput()
|
private Viewport _viewport;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
Vector2 mouseWorldPos = DisplayServer.MouseGetPosition();
|
_viewport = GetViewport();
|
||||||
|
|
||||||
var screenPosition = CameraController3D.Instance.UnprojectPosition(this.GlobalPosition);
|
|
||||||
|
|
||||||
return mouseWorldPos - screenPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 GetMouseAimInput()
|
||||||
|
{
|
||||||
|
var mouseWorldPos = GetMouseWorldPosition(this.GlobalPosition.Y);
|
||||||
|
|
||||||
|
var direction = (mouseWorldPos - this.GlobalPosition).Normalized();
|
||||||
|
|
||||||
|
return new Vector2(direction.X, direction.Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 GetMouseWorldPosition(float planeHeight = 0)
|
||||||
|
{
|
||||||
|
var mousePos = _viewport.GetMousePosition();
|
||||||
|
var rayOrigin = CameraController3D.Instance.ProjectRayOrigin(mousePos);
|
||||||
|
var rayDirection = CameraController3D.Instance.ProjectRayNormal(mousePos);
|
||||||
|
|
||||||
|
var plane = new Plane(Vector3.Up, planeHeight);
|
||||||
|
|
||||||
|
var intersection = plane.IntersectsRay(rayOrigin, rayDirection);
|
||||||
|
|
||||||
|
return intersection ?? Vector3.Zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BIN
addons/debug_draw_3d/libs/~libdd3d.windows.editor.x86_64.dll
Normal file
BIN
addons/debug_draw_3d/libs/~libdd3d.windows.editor.x86_64.dll
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue