Method RaycastClosest
- Namespace
- Box3D
- Assembly
- Box3D.NET.dll
RaycastClosest(Vector3, Vector3, QueryFilter?)
Casts a ray and returns the nearest shape it hits.
public RaycastHit RaycastClosest(Vector3 origin, Vector3 translation, QueryFilter? filter = null)Parameters
originVector3-
The start of the ray, in world space.
translationVector3-
The ray vector. Its length is the range.
filterQueryFilter?-
Which shapes the ray may hit, or null for everything.
Returns
- RaycastHit
-
The nearest hit. Check Box3D.RaycastHit.Hit before reading anything else.
Examples
var hit = world.RaycastClosest(muzzle, aim * 100.0f);
if (hit.Hit)
{
Spawn(Impact, hit.Point, hit.Normal);
}
Remarks
Ignores shapes the ray starts inside. Allocates nothing and needs no callback, so this is the one to reach for unless you need custom filtering.
Exceptions
- ObjectDisposedException
-
The world has been disposed.