Table of Contents

Struct Body

Namespace
Box3D
Assembly
Box3D.NET.dll

A rigid body: a position, an orientation and a velocity, with shapes attached to give it collision geometry.

public readonly record struct Body : IEquatable<Body>

Implements

Inherited Members

Extension Methods

Examples

Body crate = world.CreateBody(BodyDefinition.Dynamic(new Vector3(0, 10, 0)));
crate.AddBox(Box.Cube(0.5f));

crate.LinearVelocity = new Vector3(5.0f, 0.0f, 0.0f);
crate.ApplyForceToCenter(new Vector3(0.0f, 100.0f, 0.0f));

world.Step(1.0f / 60.0f);
Console.WriteLine(crate.Position);

Remarks

Like Box3D.Shape, a body is a handle rather than an object. It is a small value the world resolves, so copying is free and copies refer to the same body. It owns nothing, so it is not System.IDisposable; use Box3D.Body.Destroy to remove it, or destroy the world to remove everything.

A body with no shapes has no collision geometry and no mass. Create the body, then attach shapes to it.

Properties

AngularDamping

Gets or sets the angular damping.

AngularVelocity

Gets or sets the angular velocity, in radians per second.

Bounds

Gets the world-space bounding box covering every attached shape.

CanSleep

Gets or sets a value indicating whether the body is allowed to sleep.

CenterOfMass

Gets the world position of the centre of mass.

GravityScale

Gets or sets the multiplier applied to gravity for this body.

IsAwake

Gets or sets a value indicating whether the body is awake.

IsBullet

Gets or sets a value indicating whether the body uses continuous collision as a bullet.

IsEnabled

Gets a value indicating whether the body takes part in the simulation.

IsValid

Gets a value indicating whether this handle refers to a live body.

LinearDamping

Gets or sets the linear damping.

LinearVelocity

Gets or sets the linear velocity of the centre of mass, usually in metres per second.

LocalCenterOfMass

Gets the centre of mass in body-local space.

Mass

Gets the mass, usually in kilograms.

MotionLocks

Gets or sets the axes the body may not move along or rotate about.

Position

Gets the world position of the body origin.

Rotation

Gets the world rotation.

ShapeCount

Gets the number of shapes attached to this body.

Type

Gets or sets how the body participates in the simulation.

UserData

Gets or sets the application identifier attached to this body.

World

Gets the world this body belongs to.

Methods

AddBox(Box, ShapeDefinition?)

Attaches a box to this body.

AddCapsule(Capsule, ShapeDefinition?)

Attaches a capsule to this body.

AddCompound(CompoundGeometry, ShapeDefinition?)

Attaches a baked compound to this body, which must be static.

AddHeightField(HeightField, ShapeDefinition?)

Attaches a height field to this body, which must be static.

AddHull(ConvexHull, ShapeDefinition?)

Attaches a convex hull to this body.

AddMesh(CollisionMesh, Vector3?, ShapeDefinition?)

Attaches a triangle mesh to this body, which must be static.

AddSphere(Sphere, ShapeDefinition?)

Attaches a sphere to this body.

ApplyAngularImpulse(Vector3, bool)

Changes the angular velocity immediately.

ApplyForce(Vector3, Vector3, bool)

Applies a force at a world-space point, producing torque if it is off-centre.

ApplyForceToCenter(Vector3, bool)

Applies a force at the centre of mass, producing no rotation.

ApplyImpulse(Vector3, Vector3, bool)

Changes the velocity immediately at a world-space point, adding spin if it is off-centre.

ApplyImpulseToCenter(Vector3, bool)

Changes the velocity immediately, with no rotation.

ApplyTorque(Vector3, bool)

Applies a torque, changing angular velocity without moving the body.

Destroy()

Destroys this body along with every shape and joint attached to it.

Disable()

Removes the body from the simulation without destroying it.

Enable()

Returns a disabled body to the simulation.

GetShapes(Span<Shape>)

Copies the handles of every shape on this body into the supplied span.

GetVelocityAt(Vector3)

Gets the velocity of a point attached to this body.

MoveTowards(Vector3, Quaternion, float, bool)

Sets the velocity needed to arrive at a target pose after one time step.

RecomputeMass()

Recomputes the mass properties from the attached shapes and their densities.

SetTransform(Vector3, Quaternion?)

Teleports the body.

ToLocalPoint(Vector3)

Converts a point from world space into body-local space.

ToLocalVector(Vector3)

Converts a direction from world space into body-local space.

ToWorldPoint(Vector3)

Converts a point from body-local space into world space.

ToWorldVector(Vector3)

Converts a direction from body-local space into world space.