Click or drag to resize
DigitalRuneRigid Bodies

This section explains the basics of rigid bodies.

This topic contains the following sections:

Rigid bodies

A RigidBody is a body that is simulated by the laws of rigid body dynamics. The body has a Shape that is constant for the simulation (although the shape can be exchanged between simulation updates). No deformations are computed, therefore this type of body cannot be used to model soft objects like cloth or fluids. The rigid body also has mass properties defined in MassFrame and a Material that defines friction, bounciness and other material properties.

A rigid body can be positioned in the world using the Pose property. The rigid body moves and rotates with velocities defined by LinearVelocity and AngularVelocity.

The physics simulation updates the properties Pose, LinearVelocity, and AngularVelocity in each simulation step according to the forces and constraints that act on the rigid body. The other properties are treated as read-only by the simulation. The simulation reads properties like shape, mass, material, etc., but it does not change them.

Mass frame

Mass defines how difficult it is to change the linear velocity of a body. For example, if mass is infinite it is impossible to move a resting body or to stop a body that is already in motion. The inertia matrix is the rotational equivalent of mass. It defines how difficult it is to change the angular velocity of a body.

The mass frame defines the center of mass relative to the local coordinate system of the rigid body. For the simulation the center of mass is the center of a rigid body. The center of mass has a special importance because if forces act on an unconstrained rigid body (e.g. a body floating in outer space) any rotations will be around the center of mass. In contrast, the local space origin of a rigid body can be anywhere where the user or game editor wants it to be. For example, the origin of rigid body with a cone shape is typically at the base of the cone, whereas the center of mass of a cone is inside the cone. Or the origin of a human can be at the feet and the center of mass is near the pelvis. This distinction allows easy placement of the rigid body in a game editor.

The inertia tensor describes the "rotational mass" of a rigid body. In general, the inertia tensor is 3 x 3 matrix. But for all rigid bodies a rotated coordinate space can be found where all off-diagonal elements of the inertia matrix are 0. The axes of this rotated coordinate space are called the "principal axes". The mass frame class stores the diagonal elements of the diagonalized inertia matrix.

A mass frame is defined by the class MassFrame. The property Pose defines the position of the center of mass and the orientation of the principal axis relative to the local space of the rigid body.

When a rigid body is created and no MassFrame instance is specified in the rigid body's constructor, the mass is computed automatically. Rigid bodies also have a property AutoUpdateMass that defines whether mass frames are automatically updated when the shape of the rigid body changes.

Mass frames can be defined manually, but this is non-trivial for complex shapes. Therefore, it is recommended to use the methods MassFrameFromShapeAndDensity(Shape, Vector3F, Single, Single, Int32) or MassFrameFromShapeAndMass(Shape, Vector3F, Single, Single, Int32). The first method takes a shape and a density and computes the mass properties. The second method takes a shape and a target mass value and computes mass frame properties so that the mass is equal to the specified target mass.

For a stable simulation it is recommended that the mass ratios of different dynamic rigid bodies are small. The mass of the lightest dynamic object compared to the heaviest dynamic object should be around 1:10. In addition, all dynamic rigid bodies must have a mass less than MassFrameMassLimit. A mass value larger than MassFrameMassLimit is treated as infinite, which means the body will not respond to forces or impulses (similar to a kinematic or static body).

When a rigid body is created and no MassFrame instance is specified in the rigid body's constructor, or when the shape of a rigid body is changed and AutoUpdateMass is set, a new MassFrame is computed automatically. If the shape is very large, the mass can easily exceed the recommended mass ratio of 1:10. It can also exceed MassFrameMassLimit. In such cases it is recommended to specify a manually chosen MassFrame explicitly in the constructor of the rigid body and to set AutoUpdateMass to false.

The mass computation of complex shapes, such as triangle meshes, can take some time. To speed up the mass computation the mass frame can be substituted with the mass frame of a simpler shape. For example, the mass frame of a simple box or sphere could be used instead of the exact mass frame. Whether a body is simulated with its exact mass frame or an approximation is in many cases hardly noticeable.

For kinematic and static bodies, the MassFrame mass frame is not used by the simulation because non-dynamic bodies are treated as bodies with infinite mass. For such bodies the mass frame can be set to any value, e.g. an empty MassFrame instance:

C#
RigidBody bodyA = new RigidBody(shape, new MassFrame(), null)
{
  MotionType = MotionType.Static,
  AutoUpdateMass = false,
};
Coordinate spaces

Several coordinates spaces are used in the simulation. Here, is a short overview. Coordinate spaces are also called spaces, frames, reference frames, coordinate systems, etc.

World space (or global space) is the space of the simulation. The origin of the world space is typically the center or start of a game level. All bodies are positioned in this space. Unless noted otherwise all vector quantities (like forces, velocities, impulses) are given in world space.

Each rigid body has local space (or body space) in which its shape is defined. This space is fixed on the rigid body. The origin of this space is usually chosen so that a simple placement of the rigid body in a game editor is possible.

Each rigid body further has a mass frame which defines a coordinate space where the center of mass of the rigid body is the origin and the inertia tensor is a diagonal matrix. The axes of this space are the principal axes of the body. This space is fixed on the rigid body.

The property RigidBodyPose defines the position and orientation of the local space of a rigid body. This pose defines the position and orientation of the rigid body in world space. It can be used to transform coordinates from local space to world space.

The property RigidBodyPoseCenterOfMass defines the position and orientation of the mass frame of the rigid body. This pose defines the position of the center of mass and the orientation of the principal axes in world space. It can be used to transform coordinates from the mass frame to world space.

The change the position of a rigid body either Pose or PoseCenterOfMass can be changed. If one property is changed, the other property is updated automatically. Usually Pose is used to move a body.

MassFramePose defines the mass frame relative to the local space of the rigid body. This pose is constant for a rigid body. It defines how the RigidBodyPoseCenterOfMass can be computed from the RigidBodyPose and vice versa. Normally, MassFramePose is only used by the simulation internally.

Here are a few examples: For normal primitives that are symmetric and centered at the local space origin (such as spheres, boxes and capsules) RigidBodyPoseCenterOfMass is equal to RigidBodyPose. For symmetric shapes that are not centered at the local space origin RigidBodyPoseCenterOfMass has the same orientation as RigidBodyPose but the position is different. This is the case for a cone shape - the local space origin is at the cone base and the center of mass is inside the cone. For arbitrary triangle meshes and convex shapes RigidBodyPoseCenterOfMass is typically different from RigidBodyPose.

Static, kinematic and dynamic rigid bodies

Rigid bodies have a property MotionType, which can be set to any of the following values:

  • Dynamic: Per default, a rigid body is dynamic. This means that the motion of this body is controlled by the forces and constraints in the simulation. In detail: Forces and constraints will update the velocity of the body. The pose of the body will be updated according to the body's velocity.

  • Kinematic: A kinematic rigid body moves according to its velocities, but it is not affected by any forces or constraints in the simulation. The simulation updates the pose of a kinematic body based on its velocities. The velocities must be set by the user. The values are not changed by the simulation. Typical examples for kinematic bodies are elevators and other machinery that push other objects in the scene but cannot be pushed themselves.

  • Static: A static body has a velocity of zero and a constant position. The simulation treats static bodies as immovable. Typical examples for static bodies are terrain, walls and other fixed structures.

Note Note

Moving Kinematic Bodies: In many games, there are moving kinematic bodies, like moving platforms. To behave well in a simulation, kinematic bodies should be moved by setting velocities (LinearVelocity and AngularVelocity) and letting the simulation compute the new pose. It is not recommended to change the Pose directly. If the pose is changed manually, the body is "teleported" to the new position - for the simulation the body disappears on its old place and re-appears on the new place without any velocity-based movement in between. Collision response between a kinematic body and a dynamic body is only smooth if the kinematic body is moved using velocities.

Geometric objects and collision objects

The RigidBody class implements the interface IGeometricObject. A geometric object is an object that has a pose (= position + orientation), a shape and a scale. Each rigid body has a property RigidBodyCollisionObject that defines the collision properties of the rigid body (e.g. the CollisionGroup used for collision filtering). The collision object in turn has the property GeometricObject, which refers to the rigid body. In other words:

C#
rigidBody.CollisionObject.GeometricObject == rigidBody
See Also