API Reference

Class List

pc.RigidBodyComponent

Extends: pc.Component

The rigidbody Component, when combined with a pc.CollisionComponent, allows your Entities to be simulated using realistic physics. A rigidbody Component will fall under gravity and collide with other rigid bodies, using scripts you can apply forces to the body.

Summary

Properties

angularDampingControls the rate at which a body loses angular velocity over time.
angularFactorScaling factor for angular movement of the body in each axis.
angularVelocityDefines the rotational speed of the body around each world axis.
frictionThe friction value used when contacts occur between two bodies.
groupThe collision group this body belongs to.
linearDampingControls the rate at which a body loses linear velocity over time.
linearFactorScaling factor for linear movement of the body in each axis.
linearVelocityDefines the speed of the body in a given direction.
maskThe collision mask sets which groups this body collides with.
massThe mass of the body.
restitutionThe amount of energy lost when two objects collide, this determines the bounciness of the object.
typeThe rigid body type determines how the body is simulated.

Methods

activateForceably activate the rigid body simulation
applyForceApply an force to the body at a point.
applyForce^2Apply an force to the body at a point.
applyImpulseApply an impulse (instantaneous change of velocity) to the body at a point.
applyImpulse^2Apply an impulse (instantaneous change of velocity) to the body at a point.
applyTorqueApply torque (rotational force) to the body.
applyTorqueImpulseApply a torque impulse (rotational force applied instantaneously) to the body.
applyTorqueImpulse^2Apply a torque impulse (rotational force applied instantaneously) to the body.
applyTorque^2Apply torque (rotational force) to the body.
isActiveReturns true if the rigid body is currently actively being simulated.
isKinematicReturns true if the rigid body is of type pc.BODYTYPE_KINEMATIC
isStaticReturns true if the rigid body is of type pc.BODYTYPE_STATIC
isStaticOrKinematicReturns true if the rigid body is of type pc.BODYTYPE_STATIC or pc.BODYTYPE_KINEMATIC
teleportTeleport an entity to a new position and/or orientation
teleport^2Teleport an entity to a new position and/or orientation
teleport^3Teleport an entity to a new position and/or orientation

Inherited

Properties

enabledEnables or disables the component.

Details

Constructor

RigidBodyComponent(system, entity)

Create a new RigidBodyComponent

Parameters

systempc.RigidBodyComponentSystemThe ComponentSystem that created this Component
entitypc.EntityThe Entity this Component is attached to

Properties

NumberangularDamping

Controls the rate at which a body loses angular velocity over time.

pc.Vec3angularFactor

Scaling factor for angular movement of the body in each axis.

pc.Vec3angularVelocity

Defines the rotational speed of the body around each world axis.

Numberfriction

The friction value used when contacts occur between two bodies. A higher value indicates more friction.

Numbergroup

The collision group this body belongs to. Combine the group and the mask to prevent bodies colliding with each other.

NumberlinearDamping

Controls the rate at which a body loses linear velocity over time.

pc.Vec3linearFactor

Scaling factor for linear movement of the body in each axis.

pc.Vec3linearVelocity

Defines the speed of the body in a given direction.

Numbermask

The collision mask sets which groups this body collides with. It is a bitfield of 16 bits, the first 8 bits are reserved for engine use.

Numbermass

The mass of the body. This is only relevant for pc.BODYTYPE_DYNAMIC bodies, other types have infinite mass.

Numberrestitution

The amount of energy lost when two objects collide, this determines the bounciness of the object. A value of 0 means that no energy is lost in the collision, a value of 1 means that all energy is lost. So the higher the value the less bouncy the object is.

Stringtype

The rigid body type determines how the body is simulated. Can be:

  • pc.BODYTYPE_STATIC: infinite mass and cannot move.
  • pc.BODYTYPE_DYNAMIC: simulated according to applied forces.
  • pc.BODYTYPE_KINEMATIC: infinite mass and does not respond to forces but can still be moved by setting their velocity or position.

Methods

activate()

Forceably activate the rigid body simulation

applyForce(x, y, z, [px], [py], [pz])

Apply an force to the body at a point. By default, the force is applied at the origin of the body. However, the force can be applied at an offset this point by specifying a world space vector from the body's origin to the point of application.

// EXAMPLE 1: Apply an approximation of gravity at the body's center
this.entity.rigidbody.applyForce(0, -10, 0);

// EXAMPLE 2: Apply an approximation of gravity at 1 unit down the world Z from the center of the body
this.entity.rigidbody.applyForce(0, -10, 0, 0, 0, 1);

Parameters

xNumberThe x component of the force to apply, in world space.
yNumberThe y component of the force to apply, in world space.
zNumberThe z component of the force to apply, in world space.
pxNumberThe x component of a world space offset from the body's position where the force is applied.
pyNumberThe y component of a world space offset from the body's position where the force is applied.
pzNumberThe z component of a world space offset from the body's position where the force is applied.

applyForce^2(force, [relativePoint])

Apply an force to the body at a point. By default, the force is applied at the origin of the body. However, the force can be applied at an offset this point by specifying a world space vector from the body's origin to the point of application.

// EXAMPLE 1: Apply a force at the body's center
// Calculate a force vector pointing in the world space direction of the entity
var force = this.entity.forward.clone().scale(100);

// Apply the force
this.entity.rigidbody.applyForce(force);

// EXAMPLE 2: Apply a force at some relative offset from the body's center
// Calculate a force vector pointing in the world space direction of the entity
var force = this.entity.forward.clone().scale(100);

// Calculate the world space relative offset
var relativePos = new pc.Vec3();
var childEntity = this.entity.findByName('Engine');
relativePos.sub2(childEntity.getPosition(), this.entity.getPosition());

// Apply the force
this.entity.rigidbody.applyForce(force, relativePos);

Parameters

forcepc.Vec3The force to apply, in world space.
relativePointpc.Vec3A world space offset from the body's position where the force is applied.

applyImpulse(x, y, z, [px], [py], [pz])

Apply an impulse (instantaneous change of velocity) to the body at a point.

Parameters

xNumberThe x component of the impulse to apply, in world space.
yNumberThe y component of the impulse to apply, in world space.
zNumberThe z component of the impulse to apply, in world space.
pxNumberThe x component of the point at which to apply the impulse, in local space (relative to the Entity).
pyNumberThe y component of the point at which to apply the impulse, in local space (relative to the Entity).
pzNumberThe z component of the point at which to apply the impulse, in local space (relative to the Entity).

applyImpulse^2(impulse, [relativePoint])

Apply an impulse (instantaneous change of velocity) to the body at a point.

Parameters

impulsepc.Vec3The impulse to apply, in world space.
relativePointpc.Vec3The point at which to apply the impulse, in local space (relative to the entity).

applyTorque(x, y, z)

Apply torque (rotational force) to the body.

Parameters

xNumberThe x component of the torque to apply, in world space.
yNumberThe y component of the torque to apply, in world space.
zNumberThe z component of the torque to apply, in world space.

applyTorqueImpulse(x, y, z)

Apply a torque impulse (rotational force applied instantaneously) to the body.

Parameters

xNumberThe x component of the torque impulse to apply, in world space.
yNumberThe y component of the torque impulse to apply, in world space.
zNumberThe z component of the torque impulse to apply, in world space.

applyTorqueImpulse^2(torqueImpulse)

Apply a torque impulse (rotational force applied instantaneously) to the body.

Parameters

torqueImpulsepc.Vec3The torque impulse to apply, in world space.

applyTorque^2(force)

Apply torque (rotational force) to the body.

Parameters

forcepc.Vec3The torque to apply, in world space.

isActive()

Returns true if the rigid body is currently actively being simulated. i.e. not 'sleeping'

Returns

Boolean True if the body is active

isKinematic()

Returns true if the rigid body is of type pc.BODYTYPE_KINEMATIC

Returns

Boolean True if kinematic

isStatic()

Returns true if the rigid body is of type pc.BODYTYPE_STATIC

Returns

Boolean True if static

isStaticOrKinematic()

Returns true if the rigid body is of type pc.BODYTYPE_STATIC or pc.BODYTYPE_KINEMATIC

Returns

Boolean True if static or kinematic

teleport(position, [angles])

Teleport an entity to a new position and/or orientation

Parameters

positionpc.Vec3The new position
anglespc.Vec3THe new set of Euler angles

teleport^2(position, [rotation])

Teleport an entity to a new position and/or orientation

Parameters

positionpc.Vec3The new position
rotationpc.QuatThe new rotation

teleport^3(x, y, z, [x], [y], [z])

Teleport an entity to a new position and/or orientation

Parameters

xNumberThe new position x value
yNumberThe new position y value
zNumberThe new position z value
xNumberThe new x angle value
yNumberThe new y angle value
zNumberThe new z angle value

Inherited

Properties

Booleanenabled

Enables or disables the component.