Skip to content

Commit 2dfc3ea

Browse files
committed
Raycast point
1 parent 14265d0 commit 2dfc3ea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Scripts/Extensions/VectorExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,27 @@ public static bool RaycastPoint(this Plane plane, Ray ray, out Vector3 point)
557557
}
558558
}
559559

560+
public static bool RaycastPoint(this Plane plane, Vector3 start, Vector3 end, out Vector3 point)
561+
{
562+
var ray = new Ray(start, end - start);
563+
if (plane.Raycast(ray, out var d))
564+
{
565+
if (Mathf.Abs(d) >= (end - start).magnitude)
566+
{
567+
point = Vector3.zero;
568+
return false;
569+
}
570+
571+
point = ray.origin + ray.direction * d;
572+
return true;
573+
}
574+
else
575+
{
576+
point = Vector3.zero;
577+
return false;
578+
}
579+
}
580+
560581
public static Vector3? Intersect(this Plane plane, Ray ray)
561582
{
562583
float enter;

0 commit comments

Comments
 (0)