PhysicsRigidBody

lumin. PhysicsRigidBody

Defines the mass and movement properties of a physics object. A rigid body has no inherent shape,
one or more PhysicsShapes need to be added to it.

A rigid body is one of 3 types: static, kinematic, or dynamic
static : The body never moves.
kinematic : The body can be moved by external systems, such as animation, but is not
affected by forces or collisions.
dynamic : The body is affected by forces and collisions.

It is important that apart from their initial position, static and dynamic bodies should not
have their positions changed by calls to setLocalPosition, etc. This will cause unexpected
results in the simulation.

Methods

addShape(shape, positionopt, rotationopt) → {number}

Adds a shape to the body. A shape may not be added to the body after it has been added to a Prism.

Parameters:
Name Type Attributes Default Description
shape lumin.PhysicsShape

The shape to add.

position vec3 <optional>
VEC3_ZERO

Offset from the body's location to place the shape.

rotation quat <optional>
QUAT_IDENTITY

Rotation of the shape relative to the body's orientation.

Returns:

Id of the shape for the body. INVALID_PHYSICS_ID if the shape was not added.

Type
number

applyForce(type, force)

Applies a force to the body. The force will only be applied for the current frame; to apply a
continuous force, this function must be called every frame.

Parameters:
Name Type Description
type lumin.physics.ForceType

Type of force to apply (force or impulse).

force vec3

Amount of force. Units depend on the force type.

applyForceAtPos(type, force, pos)

Applies a force to the body at a given position. If the force is not at the center of mass, this
will result in a torque being applied to the body as well. Both the force and position are in
volume-space reference frame. The force will only be applied for the current frame; to apply a
continuous force, this function must be called every frame.

Parameters:
Name Type Description
type lumin.physics.ForceType

Type of force to apply (force or impulse).

force vec3

Amount of force. Units depend on the force type.

pos vec3

Position to apply the force

applyLocalForceAtPos(type, force, pos)

Applies a force to the body at a given position. If the force is not at the center of mass, this
will result in a torque being applied to the body as well. Both the force and position are in
local-space of the body reference frame. The force will only be applied for the current frame;
to apply a continuous force, this function must be called every frame.

Parameters:
Name Type Description
type lumin.physics.ForceType

Type of force to apply (force or impulse).

force vec3

Amount of force. Units depend on the force type.

pos vec3

Position to apply the force

applyTorque(type, force)

Applies a torque to the body. The torque will only be applied for the current frame; to apply a
continuous torque, this function must be called every frame.

Parameters:
Name Type Description
type lumin.physics.ForceType

Type of torque to apply (force or impulse).

force vec3

Amount of torque. Units depend on the force type.

clearColliderFlag(flag)

Clears a single collider flag for the body.

Parameters:
Name Type Description
flag number

Collider flag, in the range of 0 - 31.

clearCollidesWithFlag(flag)

Clears a single collides with flag for the body.

Parameters:
Name Type Description
flag number

Collides with flag, in the range of 0 - 31.

clearForce()

Clears all linear forces on the body.

clearTorque()

Clears all angular forces on the body.

getAngularDamping() → {number}

Returns angular damping coefficient being applied to the body.

Returns:

Damping

Type
number

getAngularVelocity() → {vec3}

Returns the angular velocity of the body, in rad/sec.

Returns:

velocity

Type
vec3

getBodyType() → {lumin.physics.RigidBodyType}

Returns the rigid body type (static/kinematic/dynamic).

Returns:

The body type.

Type
lumin.physics.RigidBodyType

getCenterOfMass() → {vec3}

Returns the center of mass of the body.

Returns:

Center of mass.

Type
vec3

getColliderFlags() → {number}

Returns the collider flags for the body.

Returns:

The collider flags.

Type
number

getCollidesWithFlags() → {number}

Returns the collides with flags for the body.

Returns:

The collides with flags.

Type
number

getInertiaTensor() → {vec3}

Returns the inertia tensor of the body.

Returns:

Inertia tensor.

Type
vec3

getLinearDamping() → {number}

Returns linear damping coefficient being applied to the body.

Returns:

Damping

Type
number

getLinearVelocity() → {vec3}

Returns the linear velocity of the body, in meter/sec.

Returns:

velocity

Type
vec3

getMass() → {number}

Returns the mass of the rigid body.

Returns:

Mass, in kilograms.

Type
number

getMaxAngularVelocity() → {number}

Returns the maximum angular velocity of the body.

Returns:

Max velocity

Type
number

getSleepThreshold() → {number}

Returns the sleep threshold of the body.

Returns:

Threshold

Type
number

isColliderFlagSet(flag) → {boolean}

Returns if a given collider flag is set.

Parameters:
Name Type Description
flag number

Flag value, in the range of 0 - 31.

Returns:

true if the flag is set.

Type
boolean

isCollidesWithFlagSet(flag) → {boolean}

Returns if a given collides with flag is set.

Parameters:
Name Type Description
flag number

Flag value, in the range of 0 - 31.

Returns:

true if the flag is set.

Type
boolean

lockAxes(linear, angular)

Prevents motion on the given axes. Values can be or'ed together to prevent motion on multiple axes.

Parameters:
Name Type Description
linear lumin.physics.AxisLock

Linear axes to lock

angular lumin.physics.AxisLock

Angular axes to lock

node() → {lumin.Node}

Get the Node this RigidBody is attached to.

Returns:

the Node pointer.

Type
lumin.Node

removeShape(id) → {boolean}

Removes a shape from the body. A shape may not be removed from the body after it has been added to a Prism.

Parameters:
Name Type Description
id number

Id of the shape to remove.

Returns:

true if the shape was removed

Type
boolean

setAngularDamping(damping)

Sets angular damping coefficient being applied to the body. This can be used to simulate things
like rolling friction.

Parameters:
Name Type Description
damping number

Damping coefficient

setAngularVelocity(velocity)

Sets the angular velocity of the body, in rad/sec.

Parameters:
Name Type Description
velocity vec3

setBodyType(type)

Sets the rigid body type (static/kinematic/dynamic). Changing this may result in the loss of
data for the body in the simulation. The preferred way to change the body type is to remove
the body from its volume, change the type, and re-add to the volume.

Parameters:
Name Type Description
type lumin.physics.RigidBodyType
Returns:

The body type.

setCenterOfMass(com)

Sets the center of mass of the body. Note setting it outside the body's area as defined by
the shapes attached to it may result in an unstable simulation.

Parameters:
Name Type Description
com vec3

Center of mass

setColliderFlag(flag)

Sets a single collider flag for the body.

Parameters:
Name Type Description
flag number

Collider flag, in the range of 0 - 31.

setColliderFlags(flags)

Sets the collider flags for the body. If the collider flags of one body anded with the
collides with flags of another body is 0, the bodies will not collide.

Parameters:
Name Type Description
flags number

Collider flags.

setCollidesWithFlag(flag)

Sets a single collides with flag for the body.

Parameters:
Name Type Description
flag number

Collides with flag, in the range of 0 - 31.

setCollidesWithFlags(flags)

Sets the collides with flags for the body. If the collider flags of one body anded with the
collides with flags of another body is 0, the bodies will not collide.

Parameters:
Name Type Description
flags number

Collides with flags.

setEnableCCD(enable)

Enable/disable continuous collision detection (CCD) for this body. Enabling CCD can be used to
prevent a body from "tunneling" through another due to it moving too fast.

IMPORTANT: Physics must have been enabled with the solverType initialization data set to
kFastNormal or kFastFast for this to have an effect.

Parameters:
Name Type Description
enable boolean

Flag to enable CCD on the body.

setIgnoreGravity(ignore)

Flags the body as ignoring gravity.

Parameters:
Name Type Description
ignore boolean

If true, the body won't be affected by gravity.

setInertiaTensor(tensor)

Sets the inertia tensor of the body. A value of 0 is the equivalent of infinite inertia on
the axis.

Parameters:
Name Type Description
tensor vec3

Inertia tensor.

setLinearDamping(damping)

Sets linear damping coefficient being applied to the body. This can be used to simulate things
like air resistance.

Parameters:
Name Type Description
damping number

Damping coefficient

setLinearVelocity(velocity)

Sets the linear velocity of the body, in meter/sec.

Parameters:
Name Type Description
velocity vec3

setMass(massKg)

Sets the mass of the rigid body.

Parameters:
Name Type Description
massKg number

Mass, in kilograms. Must be > 0.

setMaxAngularVelocity(velocity)

Sets the maximum angular velocity of the body. This helps keep the simulation stable; it can become
unstable if the object rotates too fast.

Parameters:
Name Type Description
velocity number

Max velocity

setSleepThreshold(threshold)

Sets the sleep threshold of the body. This controls when the body is marked to be stopped
simulating due to lack of motion.

Parameters:
Name Type Description
threshold number

Sleep threshold value