Method Raycast<TCallback>
- Namespace
- Box3D
- Assembly
- Box3D.NET.dll
Raycast<TCallback>(Vector3, Vector3, ref TCallback, QueryFilter?)
Casts a ray through the world, reporting every shape it reaches to a callback.
public void Raycast<TCallback>(Vector3 origin, Vector3 translation, ref TCallback callback, QueryFilter? filter = null) where TCallback : struct, IRaycastCallbackParameters
originVector3-
The start of the ray, in world space.
translationVector3-
The ray vector. Its length is the range, and hit fractions are relative to it.
callbackTCallback-
The callback, passed by reference so that anything it records is visible afterwards.
filterQueryFilter?-
Which shapes the ray may hit, or null for everything.
Type Parameters
TCallback-
The callback type. A struct, so the call is resolved statically and nothing is allocated.
Examples
struct CountHits : IRaycastCallback
{
public int Count;
public RaycastAction OnHit(in RaycastHit hit)
{
Count++;
return RaycastAction.Continue;
}
}
var callback = new CountHits();
world.Raycast(Vector3.Zero, new Vector3(100.0f, 0.0f, 0.0f), ref callback);
Remarks
Shapes arrive in no particular order. For the nearest hit either return Box3D.RaycastAction.ClipTo(System.Single) from the callback or use Box3D.PhysicsWorld.RaycastClosest(System.Numerics.Vector3,System.Numerics.Vector3,System.Nullable{Box3D.QueryFilter}).
Exceptions
- ObjectDisposedException
-
The world has been disposed.