Class PhysicsQueries2D
Stateless helper methods for common Box2D query patterns. These wrappers avoid any Stride engine types and operate directly on world ids and primitive math structs only.
public static class PhysicsQueries2D
- Inheritance
-
PhysicsQueries2D
Methods
CastCircleClosest(B2WorldId, Vector2, float, Vector2, B2QueryFilter)
Sweeps a circle (or a point, when radius is zero) from center
along translation and returns the closest thing it strikes.
public static ShapeCastHit? CastCircleClosest(B2WorldId worldId, Vector2 center, float radius, Vector2 translation, B2QueryFilter filter)
Parameters
worldIdB2WorldIdTarget Box2D world.
centerVector2World-space centre of the circle at the start of the sweep.
radiusfloatCircle radius; zero casts a point.
translationVector2The sweep, as a world-space displacement.
filterB2QueryFilterCategory and mask bits the struck shapes must satisfy.
Returns
- ShapeCastHit?
The closest hit, or null when the sweep is clear.
CastSegmentClosest(B2WorldId, Vector2, Vector2, Vector2, B2QueryFilter)
Sweeps a line segment from a to b along
translation and returns the closest thing it strikes.
public static ShapeCastHit? CastSegmentClosest(B2WorldId worldId, Vector2 a, Vector2 b, Vector2 translation, B2QueryFilter filter)
Parameters
worldIdB2WorldIdTarget Box2D world.
aVector2One end of the segment at the start of the sweep, in world space.
bVector2The other end.
translationVector2The sweep, as a world-space displacement.
filterB2QueryFilterCategory and mask bits the struck shapes must satisfy.
Returns
- ShapeCastHit?
The closest hit, or null when the sweep is clear.
CastShapeClosest(B2WorldId, ref B2ShapeProxy, Vector2, B2QueryFilter)
Sweeps any convex proxy (see b2MakeProxy) along translation and returns
the closest thing it strikes. The circle and segment overloads build the proxy for you.
public static ShapeCastHit? CastShapeClosest(B2WorldId worldId, ref B2ShapeProxy proxy, Vector2 translation, B2QueryFilter filter)
Parameters
worldIdB2WorldIdTarget Box2D world.
proxyB2ShapeProxyThe shape to sweep, already in world space.
translationVector2The sweep, as a world-space displacement.
filterB2QueryFilterCategory and mask bits the struck shapes must satisfy.
Returns
- ShapeCastHit?
The closest hit, or null when the sweep is clear.
OverlapAABB(B2WorldId, Vector2, Vector2)
Collects all unique bodies whose shapes overlap the axis-aligned box defined by lowerBound and upperBound.
public static List<B2BodyId> OverlapAABB(B2WorldId worldId, Vector2 lowerBound, Vector2 upperBound)
Parameters
worldIdB2WorldIdTarget Box2D world.
lowerBoundVector2Lower corner of the AABB.
upperBoundVector2Upper corner of the AABB.
Returns
- List<B2BodyId>
List of body ids (no duplicates).
OverlapCircle(B2WorldId, Vector2, float)
Collects all unique bodies whose shapes overlap a circle centered at center with radius.
public static List<B2BodyId> OverlapCircle(B2WorldId worldId, Vector2 center, float radius)
Parameters
worldIdB2WorldIdTarget Box2D world.
centerVector2World-space circle center.
radiusfloatCircle radius.
Returns
- List<B2BodyId>
List of body ids (no duplicates).
OverlapCircle(B2WorldId, Vector2, float, B2QueryFilter)
Collects all unique bodies whose shapes overlap a circle centered at center with radius,
restricted to shapes whose category bits pass filter.
public static List<B2BodyId> OverlapCircle(B2WorldId worldId, Vector2 center, float radius, B2QueryFilter filter)
Parameters
worldIdB2WorldIdTarget Box2D world.
centerVector2World-space circle center.
radiusfloatCircle radius.
filterB2QueryFilterCategory and mask bits the overlapped shapes must satisfy.
Returns
- List<B2BodyId>
List of body ids (no duplicates).
OverlapPoint(B2WorldId, Vector2, float)
Tests whether any shape overlaps the given point by constructing a tiny AABB around it.
public static B2BodyId? OverlapPoint(B2WorldId worldId, Vector2 point, float querySize = 0.1)
Parameters
worldIdB2WorldIdTarget Box2D world.
pointVector2The point to test.
querySizefloatHalf-extent of the temporary AABB used for the broad-phase query.
Returns
- B2BodyId?
The first body id whose shape actually contains the point; null if none.
RaycastAll(B2WorldId, Vector2, Vector2, float)
Performs a raycast returning every hit encountered along the segment starting at origin in direction up to maxDistance.
public static List<QueryRaycastHit> RaycastAll(B2WorldId worldId, Vector2 origin, Vector2 direction, float maxDistance)
Parameters
worldIdB2WorldIdTarget Box2D world.
originVector2World-space ray origin.
directionVector2Normalized direction vector.
maxDistancefloatMaximum ray length.
Returns
- List<QueryRaycastHit>
List of raw hit data (unsorted). Empty when nothing is hit.
RaycastClosest(B2WorldId, Vector2, Vector2, float)
Performs a closest-hit raycast against every shape in worldId along a segment starting at origin in direction up to maxDistance.
public static (bool hit, B2BodyId bodyId, B2ShapeId shapeId, Vector2 point, Vector2 normal, float fraction) RaycastClosest(B2WorldId worldId, Vector2 origin, Vector2 direction, float maxDistance)
Parameters
worldIdB2WorldIdTarget Box2D world.
originVector2World-space ray origin.
directionVector2Normalized direction vector.
maxDistancefloatMaximum ray length.