Skip to content

Physics

Updated

Physics makes a world feel solid. With physics, a crate dropped from a shelf falls, lands on the floor, tips over and comes to rest; a ball bounces off a wall; a door swings on its hinge; and a goal knows when the ball crosses its line. You describe what an entity is made of (its shape, its weight, how bouncy it is) and the physics simulation works out how it moves, every frame, in play.

This section explains how to set up physical entities in a scene and how a Behavior script pushes them, listens to their contacts and links them together.

  • Rigid body. A Rigid Body component turns an entity into something the simulation moves. “Rigid” means its shape never bends: it moves and turns as one piece. An entity has at most one rigid body.

  • Body type. Every rigid body is one of three kinds. A dynamic body is moved by gravity, forces and collisions: crates, balls, debris. A kinematic body is moved by your code and pushes dynamic bodies out of its way, but nothing pushes it back: lifts, moving platforms, sliding doors. A fixed body never moves: floors, walls, rocks.

  • Collider. A collider is the shape physics uses for an entity: a box, a sphere, a capsule, a cylinder, a cone, a convex hull or the exact triangles of a mesh. Physics never looks at what is drawn, only at colliders, which is why they can be much simpler than the visible model.

  • Implicit fixed body. An entity with colliders but no Rigid Body gets a fixed body automatically. This is how you make static scenery such as floors and walls: just add a collider.

  • Sensor (trigger). A collider with sensor on detects overlaps but never pushes anything. Use it for zones: a goal line, a checkpoint, a pressure plate.

  • Collision events. When colliders start or stop touching, the entity sends PhysicsCollider::collision-enter, collision-exit, intersection-enter and intersection-exit events. A script receives them through a Signal Emitter on that entity.

  • Joint. A joint links rigid bodies so they move together: welded, hinged, sliding, on a ball and socket, tied by a rope or a spring. Joints go on a group and link the bodies inside it.

  • Physics layer. Every collider sits on one of up to 16 physics layers. The project’s collision matrix says, for each pair of layers, whether their colliders collide, pass through each other while still reporting the overlap, or ignore each other entirely.

  • Play only. Physics steps only in play. In the editor, bodies stay exactly where you placed them.

Physics runs as a fixed-rate simulation that sits next to rendering:

  1. Building. When play starts, every entity with a Rigid Body or a collider gets a body in the physics world. Its colliders are combined into one compound shape. A Rigid Body with no collider gets one box fitted to the entity’s mesh.
  2. Stepping. The simulation advances in fixed steps (60 per second unless the project’s physics settings say otherwise). In each step it applies gravity and forces, detects contacts and resolves them so bodies do not overlap.
  3. Drawing. The display runs at its own rate (60, 72, 90, 120 Hz…), so a frame can contain no step or several. A moving body is drawn between the poses of its last two steps, so it moves evenly at any display rate. What you see is at most one step behind the simulation.
  4. Events. During each step, contacts that begin or end are handed to the entity’s Signal Emitters, which put them on the event bus for your scripts.

A script interacts with this loop in four ways:

You want to You call Read
Push, kick, spin or throw a body applyImpulse, addForce, setLinearVelocity… on PhysicsRigidBodyComponent Forces and impulses
Move a body to an exact place teleport, moveKinematic, setKinematicTarget, or the entity’s setPosition Rigid bodies and colliders
React when things touch on(signal, …) with EventType.PhysicsCollider.* Collisions and triggers
Ask “what is along this line?” PhysicsRaycaster Picking and raycasts

This walkthrough makes a ball that jumps when the player presses Space and reports each time it lands.

  1. Add a Primitive Mesh with a box shape, scale it into a wide, flat floor and add a Box Collider to it. With no Rigid Body, it becomes fixed scenery.

  2. Add a second Primitive Mesh with a sphere shape, named Ball, a metre above the floor. Add a Rigid Body (type dynamic) and a Sphere Collider. Set the collider’s restitution to 0.4 so it bounces a little.

  3. On the ball, add a Signal Emitter and set its signal to ball. Without it, the ball’s contact events go nowhere.

  4. Add a Behavior to the ball with this script:

    BouncyBall.jx
    #pragma lifecycle(startup, update)
    let body;
    function startup() {
    body = self.parent.getComponent(PhysicsRigidBodyComponent);
    // The ball's Signal Emitter puts its collider events on 'ball'.
    on('ball', (event) => {
    if (event.eventType === EventType.PhysicsCollider.CollisionEnter) {
    log('Landed on', findEntity(event.data.otherEntityId || '')?.name ?? 'something');
    }
    });
    }
    function update() {
    if (Input.keyboard.isKeyReleased(Key.Space)) {
    body.applyImpulse({ x: 0, y: 4, z: 0 });
    }
    }
  5. Enter play. The ball drops onto the floor and logs Landed on Floor. Each press of Space throws it up again.

What each part does:

  • getComponent(PhysicsRigidBodyComponent) finds the ball’s body once, in startup, so update does not search for it every frame.
  • on('ball', …) listens to everything the ball’s Signal Emitter sends. The eventType check keeps only the moment a solid contact begins.
  • event.data.otherEntityId is the id of what the ball touched; findEntity turns it back into an entity.
  • applyImpulse changes the ball’s momentum instantly, like a kick. It is a change of momentum, so a heavier ball needs a bigger impulse to reach the same height.
If you want… Use… Read
An object that falls, rolls and is pushed A dynamic Rigid Body and a simple collider Rigid bodies and colliders
A floor, wall or other scenery that never moves A collider alone (implicit fixed body) Rigid bodies and colliders
A lift or moving platform your script drives A kinematic Rigid Body and setKinematicTarget Rigid bodies and colliders
To kick, launch, spin or steer a body Impulses, forces and velocities Forces and impulses
To know when something touches or enters an area Collision events, sensor colliders Collisions and triggers
A door hinge, a pendulum, a rope or a spring A joint on a group Joints
Some objects to pass through others Physics layers Physics layers
A walking player or NPC A Character Controller, not a Rigid Body Movement
Real-world floors and tables to catch objects in AR XR Plane Collider and XR Mesh Collider XR world
GlobalWhat it is
PhysicsRigidBodyComponentBody half of the physics split: the rigid-body definition for an entity. Carries only body-level params (kind, damping, sleeping, CCD, gravity) — shapes and materials live on PhysicsColliderComponent. Owns the imperative Rapier body construction (buildBody) and control (impulses/forces/velocity) over the live body it holds; the r3f PhysicsBridge hands it the world + module and drives its per-step sync. Pair with a collider component for a custom shape, or add it alone to get an auto cuboid fitted to the mesh.
PhysicsColliderComponentBase of every collider shape: self.getComponents(PhysicsColliderComponent) lists them all.
BoxColliderComponentA box. Without a size it fits the entity's mesh bounds, the usual choice on a model; with one it is that size, centred on offset.
SphereColliderComponentA sphere.
CapsuleColliderComponentA capsule: height is the total, end caps included.
CylinderColliderComponentA cylinder.
ConeColliderComponentA cone, its tip up.
ConvexHullColliderComponentThe convex hull around the entity's own meshes: works on moving bodies, but fills in concave parts (a bowl collides as a solid lump).
MeshColliderComponentThe entity's exact triangles: precise, for static scenery such as terrain and buildings. A moving body cannot use one; there it falls back to the convex hull, with a warning.
PhysicsFixedJointComponentOpt-in marker for a container (typically a GroupEntity): when present, rigidly welds together every descendant entity that owns a live rigid body, preserving their current relative poses (a compound assembly). The first rigid body is the anchor; each other body gets one Rapier fixed joint back to it. Descendants without a PhysicsRigidBodyComponent have no body and are simply skipped. The joint frame on the anchor is its own body frame; the frame on the linked body is the anchor's pose expressed in the linked body's local space, so the solver holds them exactly as bound.
PhysicsRevoluteJointComponentOpt-in marker for a container (typically a GroupEntity): when present, links every descendant entity that owns a live rigid body to the first one with a Rapier revolute (hinge) joint. The pivot is pinned and all relative rotation is locked except about the shared PhysicsRevoluteJointProps.axis — modelling wheels, fans, doors. Rapier's revolute takes a single local axis shared by both frames, so it is expressed in the anchor's local frame; linked bodies should share the anchor's orientation at bind time (the usual authoring for hinges). Descendants without a PhysicsRigidBodyComponent are simply skipped.
PhysicsPrismaticJointComponentOpt-in marker for a container (typically a GroupEntity): when present, links every descendant entity that owns a live rigid body to the first one with a Rapier prismatic (slider) joint. All relative rotation is locked and relative translation is allowed only along the shared PhysicsPrismaticJointProps.axis — modelling pistons, drawers, elevators. Rapier's prismatic takes a single local axis shared by both frames, expressed in the anchor's local frame; linked bodies should share the anchor's orientation at bind time. Descendants without a PhysicsRigidBodyComponent are simply skipped. Translational counterpart of PhysicsRevoluteJointComponent.
PhysicsSphericalJointComponentOpt-in marker for a container (typically a GroupEntity): when present, links every descendant entity that owns a live rigid body to the first one with a Rapier spherical (ball-and-socket) joint sharing a common pivot — translation is pinned at the pivot but the bodies rotate freely about it. Descendants without a PhysicsRigidBodyComponent are simply skipped. Mirrors PhysicsFixedJointComponent, which locks rotation too.
PhysicsRopeJointComponentOpt-in marker for a container (typically a GroupEntity): when present, ties every descendant entity that owns a live rigid body to another with a Rapier rope joint — a hard upper bound on their separation, with no force while slack (like a chain link). PhysicsLinkJointProps.topology chooses a segmented chain (default) or a star cluster. Descendants without a PhysicsRigidBodyComponent are simply skipped. Sibling of PhysicsSpringJointComponent, which instead pulls toward a rest length.
PhysicsSpringJointComponentOpt-in marker for a container (typically a GroupEntity): when present, the r3f PhysicsBridge ties every descendant entity that owns a live rigid body to another with a Rapier spring joint — a soft force proportional to the distance from PhysicsSpringJointProps.restLength, damped to settle. PhysicsLinkJointProps.topology chooses a segmented chain (default) or a star cluster. Descendants without a PhysicsRigidBodyComponent have no body and are simply skipped. Pure data; the bridge owns the Rapier wiring. Sibling of PhysicsRopeJointComponent, which instead hard-limits the maximum separation.
PhysicsRaycasterA ray against colliders, in the physics world: one query over a few simple shapes instead of every triangle, and exactly what the physics blocks. A native THREE.Raycaster too; see Raycaster for how to use it.
EventTypeEvery event type a script can hear, by who sends it: compare them rather than typing the strings.
ComponentTypeWhat it does
Box Collidercomp-box-colliderBox-shaped collision, fitted to the mesh by default.
Capsule Collidercomp-capsule-colliderCapsule-shaped collision, common for characters.
Character Controllercomp-character-controllerThe character: a capsule that walks, runs, jumps and falls, from player controls, AI or scripts.
Cone Collidercomp-cone-colliderCone-shaped collision, tip up.
Convex Hull Collidercomp-convex-hull-colliderShrink-wrapped collision around the mesh; works on moving bodies.
Cylinder Collidercomp-cylinder-colliderCylinder-shaped collision.
Mesh Collidercomp-mesh-colliderExact triangle collision, for static scenery.
Physics Fixed Jointcomp-physics-fixed-jointWelds the bodies in a group together.
Physics Prismatic Jointcomp-physics-prismatic-jointSlider joint along one axis, like a drawer.
Physics Revolute Jointcomp-physics-revolute-jointHinge joint, like a door.
Physics Rigid Bodycomp-physics-rigid-bodyMakes the entity a physics body: dynamic, fixed or kinematic.
Physics Rope Jointcomp-physics-rope-jointKeeps bodies within a maximum distance, like a rope.
Physics Spherical Jointcomp-physics-spherical-jointLinks the bodies in a group at one pivot, free to swing around it like a ball and socket.
Physics Spring Jointcomp-physics-spring-jointSoft springy link between bodies.
Sphere Collidercomp-sphere-colliderSphere-shaped collision.
Topic Description
Rigid bodies and colliders Body types, Rigid Body props, collider shapes, compound bodies, moving bodies from a script.
Forces and impulses Kicks, pushes, spins, velocities, gravity per body, sleeping and waking.
Collisions and triggers Contact and overlap events, their data, sensors and trigger volumes.
Joints Fixed, revolute, prismatic, spherical, rope and spring joints on a group.
Physics layers Which colliders collide, overlap or ignore each other, and who reads the layers.