Class Body2DComponent
- Namespace
- Stride.CommunityToolkit.Bepu
- Assembly
- Stride.CommunityToolkit.Bepu.dll
A dynamic body confined to the XY plane.
[ComponentCategory("Physics - Bepu 2D")]
public class Body2DComponent : BodyComponent, IIdentifiable, ISimulationUpdate, IComponent<ISimulationUpdate.SimUpdateProcessor, ISimulationUpdate>, IMarkedComponent
- Inheritance
-
Body2DComponent
- Implements
- Inherited Members
Remarks
The body moves and collides in three dimensions like any other, but its position on Z and its rotation about X and Y are managed for it. Writing to them has no lasting effect: out-of-plane position and velocity are corrected before every solve, so a value assigned from game code is gone by the next step.
Rotation about X and Y is locked, not reset. A body that is already tilted about one of those axes when it attaches keeps that tilt, held at that angle for as long as it lives. Give bodies an identity rotation, or one about Z only, unless a permanent tilt is what you want.
Energy is not conserved the way a purpose-built 2D solver would conserve it. Contact resolution runs in three dimensions and can push a body along Z; that motion is discarded rather than redirected into the plane, so a little kinetic energy is lost whenever it happens. It is small enough not to show in ordinary scenes, but it is a real difference from a native 2D engine.
Bodies are still free to sleep, which is what keeps large 2D scenes cheap. Nothing here wakes a resting body.
This design has been upstreamed as Stride.BepuPhysics.Body2DComponent, and this copy keeps
the toolkit working against Stride builds that predate it. The matching name is deliberate: once
that version ships, deleting this one file switches every call site over to the engine's, because
the same code carries on resolving to it. Until then, code importing both
Stride.BepuPhysics and Stride.CommunityToolkit.Bepu must qualify which one it means.
Constructors
Body2DComponent()
Initializes a new Body2DComponent with interpolation enabled, so rendering stays smooth when the display refreshes faster than the fixed physics step.
public Body2DComponent()
Properties
ZTolerance
Gets or sets how far the body may drift off the Z = 0 plane before it is pulled back, in world units. Defaults to 0.001, one millimetre for a scene built at one unit per metre.
[DataMemberRange(0.0001, 4)]
[Display("Z tolerance", "Activity")]
public float ZTolerance { get; set; }
Property Value
Remarks
Out-of-plane velocity is always cleared; this value only controls when positional correction starts.
Exceptions
- ArgumentOutOfRangeException
The value is not finite, or is not greater than zero.
Methods
AfterSimulationUpdate(BepuSimulation, float)
Method called after the simulation has run on the 2D body.
public virtual void AfterSimulationUpdate(BepuSimulation sim, float simTimeStep)
Parameters
simBepuSimulationThe simulation that stepped this body.
simTimeStepfloatThe fixed time step, in seconds.
Remarks
Does nothing. The whole correction has already happened before the solve, in SimulationUpdate(BepuSimulation, float).
AttachInner(RigidPose, BodyInertia, TypedIndex)
protected override void AttachInner(RigidPose pose, BodyInertia shapeInertia, TypedIndex shapeIndex)
Parameters
poseRigidPoseshapeInertiaBodyInertiashapeIndexTypedIndex
SimulationUpdate(BepuSimulation, float)
Updates the simulation state of the 2D body.
public virtual void SimulationUpdate(BepuSimulation sim, float simTimeStep)
Parameters
simBepuSimulationThe simulation stepping this body.
simTimeStepfloatThe fixed time step, in seconds.
Remarks
Runs before the solver, so the corrections applied here are resolved together with every contact rather than overwriting the solver's result afterwards. Out-of-plane velocity is cleared, and once the body is further from the plane than ZTolerance a bounded velocity pulls it back. Sleeping bodies are left alone.