Rigid bodies and colliders
Updated
A Rigid Body says how an entity moves in the physics world, and its colliders say what shape it has there. Together they turn a picture into an object: something that falls, lands, slides, tips over and gets in the way of other things. This page explains the body types, the props of the Rigid Body and of every collider shape, how several colliders combine into one body, and how a script moves a physical entity without fighting the simulation.
Before you start
Section titled “Before you start”- You know how to add components to an entity and read them from a script with
getComponent. See Components. - You know the physics vocabulary from the Physics overview: rigid body, body type, collider, sensor.
- Physics runs in play only. In the editor nothing falls.
The model
Section titled “The model”The physics world is built from a few simple rules:
- One body per entity. An entity has at most one Rigid Body (
comp-physics-rigid-body). - Colliders are the shape. An entity may carry several colliders, of any shapes. Together they make one compound body that moves as a single piece.
- Colliders without a body are fixed. An entity with colliders but no Rigid Body gets an implicit fixed body. This is how floors, walls and other static scenery are made.
- A body without a collider gets a box. A Rigid Body with no collider gets one box fitted to the entity’s mesh.
- Only the entity’s own meshes count. A shape fitted to the mesh uses the entity’s own meshes. Child entities, such as decals, labels or nested objects, are not part of it; give them their own colliders if they need to collide.
A crate built from several shapes looks like this:
Crate (Primitive Mesh) ├── Rigid Body type: dynamic ├── Box Collider size 1 × 0.2 × 1, offset y 0 ├── Box Collider size 0.2 × 1 × 1, offset x -0.4 ├── Box Collider size 0.2 × 1 × 1, offset x 0.4 └── Sphere Collider radius 0.3, offset y 0.8Rigid bodies and colliders are offered on meshes, primitives, groups and snap zones. An invisible trigger or wall is simply a group with colliders.
Body types
Section titled “Body types”The Rigid Body’s type decides who moves the body.
| Type | Moved by | Pushed by other bodies | Typical use |
|---|---|---|---|
dynamic |
Gravity, forces, impulses and collisions | Yes | Crates, balls, debris, anything the player can knock over. |
kinematic |
Your script, through kinematic moves | No, but it pushes dynamic bodies | Lifts, moving platforms, sliding doors, a carried object. |
fixed |
Nothing: it never moves | No | Floors, walls, terrain, buildings. |
A Rigid Body whose props leave type out is dynamic.
Rigid Body props
Section titled “Rigid Body props”| Prop | Type | Default | Description |
|---|---|---|---|
type |
'dynamic' | 'kinematic' | 'fixed' |
'dynamic' |
Who moves the body; see Body types. |
linearDamping |
number | 0 |
Slows the body’s travel each step, like air resistance. Higher values stop it sooner. |
angular |
number | 0 |
Slows the body’s spin each step. |
gravityScale |
number | 1 |
Gravity multiplier from 0 to 1. 0 floats, 1 falls normally. |
sleep |
boolean | true |
Let the body sleep when it comes to rest, which saves work. |
continuous |
boolean | false |
Stops fast bodies passing through thin colliders between two steps, at extra cost. Turn it on for small, fast objects such as bullets. |
mass |
number | 0 |
The body’s total mass in kilograms. A positive mass is spread over its colliders by volume, so the centre of mass and the spin follow the shapes. 0 derives the mass from the collider volume. Ignored on fixed bodies. |
lockRotation |
{ x?, y?, z? } |
all unlocked | Never turn about these world axes. { x: true, z: true } keeps a body upright. Dynamic bodies only. |
lockPosition |
{ x?, y?, z? } |
all unlocked | Never move along these world axes. { y: true } keeps a body at its height. Dynamic bodies only. |
Change props from a script with setProps, for example body.setProps({ type: 'kinematic' }).
Colliders
Section titled “Colliders”Every collider shape is a component that extends PhysicsColliderComponent. They all share these props:
| Prop | Type | Default | Description |
|---|---|---|---|
offset |
{ x, y, z } |
0, 0, 0 |
Where the shape sits relative to the entity, in local units. |
rotation |
{ x, y, z } |
0, 0, 0 |
How the shape is turned relative to the entity, Euler angles in radians. |
friction |
number | 0.5 |
How much surfaces grip, from 0 (ice) to 5. Values above 1 are valid. |
restitution |
number | 0 |
Bounciness, from 0 (no bounce) to 1 (keeps all its speed). |
sensor |
boolean | false |
A sensor reports overlaps but applies no forces. See Collisions and triggers. |
collision |
integer | 0 |
The physics layer the collider is on, 0 to 15. |
The shapes and their own props:
| Component | Type | Shape props | Best for |
|---|---|---|---|
| Box Collider | comp- |
size { x, y, z }, the full size; left out, the box fits the mesh bounds. borderRadius (default 0) rounds its edges, in metres. |
Crates, walls, floors, furniture. |
| Sphere Collider | comp- |
radius (default 0.5). |
Balls, round rocks. The cheapest shape. |
| Capsule Collider | comp- |
radius (default 0.5), height (default 2), the total including its rounded caps, along local Y. |
Bottles, logs, limbs. |
| Cylinder Collider | comp- |
radius (default 0.5), height (default 1), along local Y. |
Barrels, pillars, wheels. |
| Cone Collider | comp- |
radius (default 0.5), height (default 1), tip up. |
Traffic cones, spikes. |
| Convex Hull Collider | comp- |
None: the tightest convex shape around the entity’s meshes. | Irregular moving objects. It fills hollows: a bowl collides as a solid lump. |
| Mesh Collider | comp- |
None: the entity’s exact triangles. | Static scenery such as terrain and buildings. On a moving body it falls back to a convex hull, with a warning. |
The real room in AR has two more collider shapes, the XR Plane Collider and the XR Mesh Collider, described in XR world.
Six pins with Capsule Colliders, which fit tall rounded shapes exactly, stand on a lane; every few seconds the script rolls the amber ball into them, then teleports the pins back up.
Watch the ball knock the pins over and the pins stand up again for the next roll. Drag to orbit the camera, scroll to zoom.
Traffic cones tumble onto the ground and settle on their bases or roll on their sides, because each Cone Collider has the cone's own shape, tip up. The script drops them again every few seconds.
Watch where the cones come to rest: upright, tipped over or rolling on their sides. Drag to orbit the camera, scroll to zoom.
Faceted rocks fall and tumble to rest on their flat faces: each Convex Hull Collider wraps its rock's mesh, squashed or not, as tightly as a convex shape can. The script drops them again every few seconds.
Watch the rocks bounce off each other and settle on a face, never on a corner. Drag to orbit the camera, scroll to zoom.
A big static ring has a Mesh Collider, which uses its exact triangles: marbles that land on the ring roll off it, and marbles over its hole fall straight through, which no box or convex shape would allow.
Watch the marbles over the hole drop through it and the others bounce off the ring. Drag to orbit the camera, scroll to zoom.
Several colliders on one entity
Section titled “Several colliders on one entity”Collider components allow several instances per entity. Read them all with getComponents:
const shapes = self.parent.getComponents(PhysicsColliderComponent);log(shapes.length, 'colliders');getComponent(PhysicsColliderComponent) returns the first one. PhysicsColliderComponent exists as a script global so you can find colliders of any shape, but you cannot add it: add a concrete shape such as BoxColliderComponent.
Solid shapes
Section titled “Solid shapes”A solid object is a Primitive Mesh with a collider: there is no separate collider entity.
- Box. A Box Collider without a
sizefits the mesh bounds, so it follows the Geometry when you resize it. - Sphere, cylinder. The defaults of the Sphere and Cylinder Colliders match the unit primitive (radius 0.5, height 1). Size the object with the entity’s scale and the collider follows.
- Invisible wall. A Group with a Box Collider of its own
size. - Movable. Without a Rigid Body the shape is fixed. Add one to make it fall, roll or be pushed.
Moving physical entities from a script
Section titled “Moving physical entities from a script”A body’s pose belongs to the simulation. Move it through an API the simulation understands:
| To… | Use | Notes |
|---|---|---|
| Place any body somewhere at once | body. |
The body arrives at rest. A body that would start inside the ground is raised onto it. Returns where it ended. |
| Place an entity and its body | entity., setRotation, setScale |
The transform setters move the body too. A scale change rebuilds the colliders at the new size. |
| Drive a kinematic body by a step | body. |
Queues a world-space move for the next physics step. It pushes what it touches. |
| Drive a kinematic body to a pose | body. |
The world pose it reaches by the next step. rotation is a quaternion { x, y, z, w }. |
| Push a dynamic body | Impulses, forces, velocities | See Forces and impulses. |
Vectors are plain { x, y, z } objects; a THREE.Vector3 works too.
Reading the body
Section titled “Reading the body”| Member | Description |
|---|---|
isSimulated |
true while a live body backs the component: in play, with the entity enabled. |
bodyType |
The kind driving the live body now: 'dynamic', 'kinematic' or 'fixed'. |
isKinematic |
Whether the live body is kinematic now. A grabbed dynamic body reads as kinematic while it is held. |
Edits that rebuild the body
Section titled “Edits that rebuild the body”- Editing a collider’s props, or adding or removing a collider, rebuilds the entity’s body.
- A scale change through the setters rebuilds the colliders at the new size: every axis for boxes and meshes, X for a sphere’s radius, X and Y for a capsule or a cylinder.
Smooth motion
Section titled “Smooth motion”The simulation steps at a fixed rate and the display at its own, so a moving body is drawn between the poses of its last two steps. The entity’s transform is that drawn pose, at most one step behind the simulation. Physics itself (velocities, contacts, raycasts) uses the exact pose. A teleport, or a move through the setters, shows at once instead of sliding there.
Examples
Section titled “Examples”1. Drop a shelf item on a signal
Section titled “1. Drop a shelf item on a signal”Items on a shelf start as fixed scenery. When something emits shelf/shake, the script adds a dynamic Rigid Body to each item so they all fall.
#pragma lifecycle(startup)
// Put this Behavior on the Shelf group. Each child of the shelf is a mesh with a Box Collider.let items = [];
function startup() { items = self.parent.children.filter((child) => isEntity(child) && child !== self);
on('shelf/shake', () => { for (const item of items) { if (item.getComponent(PhysicsRigidBodyComponent)) continue; item.addComponent(new PhysicsRigidBodyComponent({ type: 'dynamic', mass: 2 })); } log(`${items.length} items fall`); });}Items hung on a pegboard are fixed scenery with only a Box Collider; on shelf/shake, the script adds a dynamic Rigid Body to each one, and they fall.
Press Shake the shelf to make every item fall. Drag to orbit the camera, scroll to zoom.
self.parent.childrenlists the shelf’s direct children;isEntitykeeps only entities, skipping plain objects such as the shelf’s own mesh, andchild !== selfleaves out the Behavior itself.- Before the signal, each item has only a Box Collider, so it is fixed scenery.
addComponent(new PhysicsRigidBodyComponent({ … }))gives the item a body. Its existing Box Collider becomes that body’s shape, and gravity takes over on the next step.- The
getComponentcheck makes the handler safe to run twice.
2. A moving platform
Section titled “2. A moving platform”A kinematic platform slides back and forth between two points. Dynamic boxes resting on it are carried and pushed, and nothing can push the platform off its path.
#pragma lifecycle(startup, update)
const TRAVEL = 4; // metres from one end to the otherconst PERIOD = 6; // seconds for a full back-and-forth
let body;let start;let turn;const target = new THREE.Vector3();
// The platform has a Rigid Body with type 'kinematic' and a Box Collider.function startup() { body = self.parent.getComponent(PhysicsRigidBodyComponent); start = self.parent.position.clone(); turn = self.parent.quaternion.clone();}
function update(dt, time) { const t = (Math.sin((time / PERIOD) * M_TAU) + 1) / 2; // 0 → 1 → 0 target.copy(start); target.x += t * TRAVEL; body.setKinematicTarget(target, turn);}A kinematic platform slides back and forth with setKinematicTarget every frame, carrying the dynamic crates that rest on it.
Watch the platform carry the crates to and fro. Grab a crate and drop it back on. Drag elsewhere to orbit the camera.
- The platform’s Rigid Body is
kinematic, so gravity ignores it and dynamic bodies cannot push it. startandturnare copied once: the platform’s home position and its fixed rotation.- In
update,timeis the seconds since play began. The sine wave turns it into a smooth value going from 0 to 1 and back. setKinematicTargetasks the simulation to bring the body to that pose by the next step. Because the simulation moves it, the platform carries and pushes the dynamic bodies it touches.targetis reused every frame instead of creating a new vector.
3. Respawn objects that fall off the world
Section titled “3. Respawn objects that fall off the world”A ball knocked off the map falls for ever. This script brings it back to where it started.
#pragma lifecycle(startup, update)
const KILL_HEIGHT = -10;
let body;let home;let homeRotation;
// On a dynamic ball with a Rigid Body and a Sphere Collider.function startup() { body = self.parent.getComponent(PhysicsRigidBodyComponent); home = self.parent.position.clone(); homeRotation = self.parent.quaternion.clone();}
function update() { if (self.parent.position.y > KILL_HEIGHT) return; const landed = body.teleport(home, homeRotation); log('Respawned at', landed); emit('ball/respawned', { id: self.parent.entityId });}A ball rolls down a ramp and off its end; once it is 10 m down, teleport puts its body back at its starting place, and it rolls again.
Watch the ball roll off the ramp, fall and come back to the top. Drag to orbit the camera, scroll to zoom.
self.parent.positionis the drawn pose, which is good enough to check a height.teleportputs the body back at its start pose, at rest, so it does not keep the speed it had while falling. Writingself.parent.position.copy(home)would not work: the body would pull the entity straight back.teleportreturns where the body really ended, which can differ if the start point was inside the ground.emittells other scripts, for example a score keeper, that the ball came back.
4. Switch a body between thrown and carried
Section titled “4. Switch a body between thrown and carried”A crate can be carried by a script (kinematic) or dropped to fall freely (dynamic). Switching the type with setProps keeps its colliders.
#pragma lifecycle(startup, update)
const HOLD = new THREE.Vector3(0, 1.2, -1.5); // in front of the cameraconst held = new THREE.Vector3();const facing = new THREE.Quaternion();
let crate;let body;let carrying = false;
function startup() { crate = findEntity('Crate'); body = crate.getComponent(PhysicsRigidBodyComponent);}
function update() { if (Input.keyboard.isKeyReleased(Key.E)) { carrying = !carrying; body.setProps({ type: carrying ? 'kinematic' : 'dynamic' }); if (!carrying) body.wakeUp(); } if (!carrying || !camera) return;
held.copy(HOLD).applyMatrix4(camera.matrixWorld); camera.getWorldQuaternion(facing); body.setKinematicTarget(held, facing);}E switches a crate between kinematic, led in front of the camera with setKinematicTarget, and dynamic, falling freely; its collider is kept.
Click the scene, then press E to pick the crate up, orbit the camera, and press E again to drop it.
- Pressing E toggles between carrying and dropping.
setProps({ type })changes the body type; the crate keeps its shape. camerais the camera the player sees through.HOLDis a point in the camera’s own space;applyMatrix4(camera.matrixWorld)turns it into a world point in front of the player.- While carried,
setKinematicTargetdrags the crate to that point every frame, and the crate pushes whatever it hits. - On drop,
wakeUpmakes sure the now-dynamic crate starts falling at once.
Snippets
Section titled “Snippets”1. Inspect every collider on an entity
Section titled “1. Inspect every collider on an entity”#pragma lifecycle(startup)
function startup() { const shapes = self.parent.getComponents(PhysicsColliderComponent); for (const shape of shapes) { log(shape.type, 'sensor:', shape.props.sensor === true, 'layer:', shape.props.collisionLayer ?? 0); }
// Make every shape a little bouncier. for (const shape of shapes) shape.setProps({ restitution: 0.3 });}getComponents(PhysicsColliderComponent)returns every collider, whatever its shape, in the order they were added.typeis the component type, such ascomp-box-collider.propsholds each collider’s current props; a prop left out uses its default.setPropson a collider rebuilds the entity’s body once the edit is applied, so avoid changing colliders every frame.
Common mistakes
Section titled “Common mistakes”- Moving a body by writing its position.
entity.position.x += 1changes only the drawing; the body pulls it back. UsesetPosition,teleportor a kinematic move. - Moving a dynamic body with kinematic calls.
moveKinematicandsetKinematicTargetare for kinematic bodies. To steer a dynamic body, use forces, impulses or velocities. - A Mesh Collider on a falling object. Exact triangles only work on fixed scenery. A moving body falls back to a convex hull. Use simple shapes on dynamic bodies.
- Expecting a model’s children to collide. A fitted shape uses the entity’s own meshes only. Give child entities their own colliders.
- A fast bullet passing through a thin wall. Between two steps it may jump over the wall. Turn on
continuousCollisionfor that body only. - Rebuilding bodies every frame. Changing collider props, adding colliders or scaling an entity rebuilds its body. Do it on events, not in
update. - Adding a Rigid Body to a character. A Character Controller’s capsule is the entity’s body; the Rigid Body is ignored.
- Testing in the editor. Physics does not step there. Enter play.