Table of Contents

Class SimulationExtensions

Namespace
Stride.CommunityToolkit.Bepu
Assembly
Stride.CommunityToolkit.Bepu.dll

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

simulation BepuSimulation

The BepuSimulation to cast in.

raySegment RaySegment

The segment to cast, from Start to End.

hit HitInfo

The closest intersection when this method returns true; undefined otherwise.

collisionMask CollisionMask

Which 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 simulation is 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

simulation BepuSimulation

The BepuSimulation to cast in.

raySegment RaySegment

The segment to cast, from Start to End.

collisionMask CollisionMask

Which layers can be hit. Defaults to Everything.

Returns

List<HitInfo>

A new list of hits, empty when nothing was hit. Hits are not sorted.

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 simulation is 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

simulation BepuSimulation

The BepuSimulation to cast in.

raySegment RaySegment

The segment to cast, from Start to End.

hits ICollection<HitInfo>

The collection hits are appended to. It is not cleared first.

collisionMask CollisionMask

Which 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 simulation or hits is null.