Skip to content

Physics

Brine2D

Brine2D.Physics Namespace

Classes
BoxShape
CapsuleShape
ChainShape Chain shape for smooth static terrain. Points are in local body space. Chain shapes do not support triggers, bullet mode, mass, or non-Static body types. Sensor limitation: Box2D only generates sensor/trigger events when a sensor shape overlaps a non-sensor shape. Two IsTrigger bodies will never fire trigger events with each other. Contact event volume: each segment of a chain shape is an independent Box2D shape. On long terrain chains, a fast-moving body can simultaneously touch many segments, generating a proportional number of contact events per fixed-update tick. Keep chain point density reasonable for sections where dynamic bodies travel.
CircleShape
PhysicsLayerRegistry Maps string layer names to Box2D layer indices (0–63). Register names at startup via Register(string, int) before building any physics bodies, then use GetLayer(string) and GetMask(string) to build PhysicsQueryFilter instances and assign Brine2D.ECS.Components.PhysicsBodyComponent.Layer values by name.
PhysicsLayers A static registry that maps named physics layers to their integer index (0–63). Register layers once at startup; then use MaskFor(ReadOnlySpan<string>) to build collision masks. Thread-safe for concurrent reads after all registrations are complete.
PhysicsMaterial An immutable surface material preset that sets Brine2D.Physics.PhysicsMaterial.Friction and Brine2D.Physics.PhysicsMaterial.Restitution together on a PhysicsBodyComponent. Assign via Material.
PhysicsOptions Configuration for PhysicsWorld creation.
PhysicsServiceCollectionExtensions Extension methods for registering Box2D physics services.
PhysicsWorld Scoped wrapper around a Box2D world. One instance per scene, registered as scoped in DI. Users work entirely in pixel coordinates; the Brine2D.Physics.PhysicsWorld.PixelsPerMeter ratio is applied once via Box2D.NET.Bindings.B2.SetLengthUnitsPerMeter(System.Single) so Box2D operates in pixel space internally. Because Box2D.NET.Bindings.B2.SetLengthUnitsPerMeter(System.Single) is a process-wide global, the value is locked to the first instance and released automatically when the last world is disposed.
PolygonShape Convex polygon. Vertices are in local body space. Box2D computes the convex hull of the supplied vertices — concave or self-intersecting vertex lists are silently reduced to their convex hull in all build configurations. Ensure your vertices are already convex and wound consistently (clockwise or counter-clockwise) if the exact shape matters; Box2D may discard vertices or reorder them during hull computation. In DEBUG builds a convexity assertion is raised when non-convex input is detected so issues surface during development, but in RELEASE builds the hull is computed silently with no warning. There is no runtime convex-decomposition; for concave shapes use multiple PhysicsBodyComponent.AddSubShape calls, each with a convex PolygonShape. Maximum of MaxPolygonVertices vertices (Box2D limit).
SegmentShape Single line segment in local body space. One-sided collision: segment shapes only collide with shapes approaching from the outward normal side. The outward normal is the left-hand perpendicular of the direction Point1 → Point2 — i.e. rotating (Point2 - Point1) 90° counter-clockwise. Shapes that contact the segment from the opposite (back) side pass straight through without generating any collision response. This makes segment shapes useful for one-way platforms and directional blockers, but unsuitable for closed geometry where back-face hits must be resolved. Use cases: one-way platforms (horizontal segment, normal pointing up), directional walls, simple ramp surfaces. For smooth multi-segment terrain that avoids ghost collisions at joints, prefer ChainShape, which Box2D handles as a single continuous surface. For a two-sided collidable edge, use a very thin CapsuleShape or a narrow BoxShape. Static geometry only: dynamic bodies with segment shapes behave unpredictably under rotation and are not supported by Box2D.
ShapeDefinition Describes the geometry of a Box2D shape. Passed to Shape or AddSubShape(ShapeDefinition, bool, Nullable<float>, Nullable<float>). Shape definitions are immutable records. Changing a property (e.g. Radius, Width, Height) creates a new record value — it does not automatically update a live Box2D body. To resize a shape at runtime you must reassign Shape (or the sub-shape's Brine2D.ECS.Components.SubShape.Definition) with the new record. The physics system detects the assignment and triggers a full body rebuild on the next tick, which resets all shape IDs and clears sub-step kinematic state. Set shape dimensions once at construction time where possible.
Structs
ContactPair A single active contact between this body and another, returned by GetContacts(PhysicsBodyComponent, Span<ContactPair>, bool).
OverlapHit Result of a per-shape overlap query against the physics world.
PhysicsMassData Mass properties of a physics body at a point in time.
PhysicsQueryFilter Filter for physics queries (raycasts, shape casts, overlap tests). Mirrors the layer/mask system used by PhysicsBodyComponent.
PhysicsWorldCounters Live simulation counters for the Box2D world. Obtained via GetCounters().
PhysicsWorldProfile Timing breakdown (in milliseconds) for the last Box2D world step. Obtained via GetProfile().
PreSolveContact Contact information passed to the pre-solve filter registered with SetPreSolveFilter(Func<PreSolveContact,bool>). Return false to cancel the contact for the current step without generating collision response forces.
RaycastHit Result of a raycast against the physics world.
ShapeCastHit Result of a shape cast (sweep) against the physics world.
Enums
PhysicsBodyType Determines how a collider participates in collision resolution.