Table of Contents

Class BodyComponentExtensions

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

Extension methods for BodyComponent.

public static class BodyComponentExtensions
Inheritance
BodyComponentExtensions

Methods

LockRotation(BodyComponent, bool, bool, bool)

Stops the body turning about the chosen axes of its own frame for all practical purposes: a crate that may slide but not tumble, a figure that must stay upright, a 2D-in-3D body that turns about Z alone.

public static void LockRotation(this BodyComponent body, bool lockX, bool lockY, bool lockZ)

Parameters

body BodyComponent

The body, already in a simulation.

lockX bool

Whether to lock rotation about the body's X axis.

lockY bool

Whether to lock rotation about the body's Y axis.

lockZ bool

Whether to lock rotation about the body's Z axis.

Remarks

The inverse inertia about each locked axis is scaled down by ten thousand, the way Body2DComponent keeps its bodies in the plane, and the coupling between the axes is cleared so the free ones stay free. It is not zeroed: a tensor with a zero row is rank-deficient, and a convex hull with such a tensor corrupts Bepu's contact generation.

The inertia belongs to the attached body, so call this once the body is in a simulation, from the frame after its entity joined the scene, and again after a change of Kinematic, which gives the body its full shape inertia back. The axes are the body's own: a body that is turned when it is locked keeps that turn.

The lock is on torque, which is what collisions and impulses apply. An angular velocity written to AngularVelocity is kept whatever the inertia; a body that must stop turning as well as stay still has that velocity zeroed by the caller.

TeleportAtRest(BodyComponent, Vector3, Quaternion?)

Puts the body at a position and rotation with no motion left and awake: a reset to a start pose, a respawn, a "put it back" key.

public static void TeleportAtRest(this BodyComponent body, Vector3 position, Quaternion? rotation = null)

Parameters

body BodyComponent

The body to move.

position Vector3

Where the body's origin goes, in world units.

rotation Quaternion?

The body's orientation; null, the default, is Identity.

Remarks

Teleport(Vector3, Quaternion) alone moves the body and nothing else: it keeps its velocity, its spin and its sleep, so a body that was tumbling keeps tumbling at the new place, and one that was asleep stays where it was put without checking what is under it. This zeroes both velocities and wakes the body from a fresh sleep, so that the sleep candidacy a resting body built up before the move does not come with it: a body that was still awake but about to sleep would otherwise be put to sleep at the new place within a step or two, before gravity had moved it, because waking an awake body changes nothing and the sleeper judges candidacy on the velocity before integration.

Exceptions

ArgumentNullException

If body is null.