Added Methods to help with checking ray with a plane.
This commit is contained in:
14
GodotHelper/src/Math/Planes.cs
Normal file
14
GodotHelper/src/Math/Planes.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace GodotHelpers;
|
||||||
|
|
||||||
|
using Godot;
|
||||||
|
public static partial class SJKMath
|
||||||
|
{
|
||||||
|
public static Vector3? MouseToPlane(this Plane plane, Camera3D viewCamera, Vector2? mousePos = null)
|
||||||
|
{
|
||||||
|
var from = viewCamera.ProjectRayOrigin( mousePos ?? viewCamera.GetViewport().GetMousePosition());
|
||||||
|
var normal = viewCamera.ProjectRayNormal(mousePos ?? viewCamera.GetViewport().GetMousePosition());
|
||||||
|
return plane.IntersectsRay(from, normal);
|
||||||
|
}
|
||||||
|
public static Vector3? MouseToGroundPlane(this Camera3D viewCamera, Vector2? mousePos = null, float offset = 0) =>
|
||||||
|
(Plane.PlaneXZ with { D = offset }).MouseToPlane(viewCamera, mousePos);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user