Class SimulationExtensions
Provides extension methods for BepuSimulation that cast a RaySegment,
so a segment produced by CameraComponentExtensions.ScreenToWorldRaySegment can be handed
to Bepu directly, with no separate direction or maximum distance to work out.
public static class SimulationExtensions
- Inheritance
-
SimulationExtensions
Remarks
Bepu's own ray casts take an origin, a normalised direction and a maximum distance. A RaySegment carries the same information as two points: the origin is Start, the direction points from Start to End, and the maximum distance is Length. A segment whose two points coincide has no direction and never hits anything.
Methods
RayCast(BepuSimulation, in RaySegment, out HitInfo, CollisionMask)
Finds the closest intersection between the raySegment and the shapes in the simulation.
public static bool RayCast(this BepuSimulation simulation, in RaySegment raySegment, out HitInfo hit, CollisionMask collisionMask = CollisionMask.Everything)
Parameters
simulationBepuSimulationThe BepuSimulation to cast in.
raySegmentRaySegmenthitHitInfoThe closest intersection when this method returns true; undefined otherwise.
collisionMaskCollisionMaskWhich layers can be hit. Defaults to Everything.
Returns
- bool
true when the segment intersects a shape, false otherwise (including for a zero-length segment).
Exceptions
- ArgumentNullException
Thrown if
simulationis null.
RayCastPenetrating(BepuSimulation, in RaySegment, CollisionMask)
Collects every intersection between the raySegment and the shapes in the simulation into a new list.
public static List<HitInfo> RayCastPenetrating(this BepuSimulation simulation, in RaySegment raySegment, CollisionMask collisionMask = CollisionMask.Everything)
Parameters
simulationBepuSimulationThe BepuSimulation to cast in.
raySegmentRaySegmentcollisionMaskCollisionMaskWhich layers can be hit. Defaults to Everything.
Returns
Remarks
Allocates a list per call. For a cast that runs every frame, prefer RayCastPenetrating(BepuSimulation, in RaySegment, ICollection<HitInfo>, CollisionMask) with a reused collection.
Exceptions
- ArgumentNullException
Thrown if
simulationis null.
RayCastPenetrating(BepuSimulation, in RaySegment, ICollection<HitInfo>, CollisionMask)
Collects every intersection between the raySegment and the shapes in the simulation.
public static void RayCastPenetrating(this BepuSimulation simulation, in RaySegment raySegment, ICollection<HitInfo> hits, CollisionMask collisionMask = CollisionMask.Everything)
Parameters
simulationBepuSimulationThe BepuSimulation to cast in.
raySegmentRaySegmenthitsICollection<HitInfo>The collection hits are appended to. It is not cleared first.
collisionMaskCollisionMaskWhich layers can be hit. Defaults to Everything.
Remarks
Hits are not sorted; there are no guarantees about the order they are returned in.
Exceptions
- ArgumentNullException
Thrown if
simulationorhitsis null.