SegmentShape Class
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.
public sealed record SegmentShape : Brine2D.Physics.ShapeDefinition, System.IEquatable<Brine2D.Physics.SegmentShape>
Inheritance System.Object → ShapeDefinition → SegmentShape
Implements System.IEquatable<SegmentShape>
| Constructors | |
|---|---|
| SegmentShape(Vector2, Vector2) | 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. |
| Properties | |
|---|---|
| Offset | Local-space offset applied to both Point1 and Point2 when the shape is built. Use this to position the segment away from the body origin on compound bodies without recomputing both points manually. Default is System.Numerics.Vector2.Zero. |
| Point1 | Start of the segment in local body space (pixels). |
| Point2 | End of the segment in local body space (pixels). |