Added Methods to help with checking ray with a plane.

This commit is contained in:
2026-07-05 13:48:32 -04:00
parent 9f968fd814
commit fa5bc913a4

View 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);
}