EngineIntermediate

Physics, collisions, and triggers

Apply forces, receive collision callbacks, configure triggers, and query the world.

Rigid-body control

  • addForce(x, y, z) applies a force for the next physics step. Call it every frame from update to keep pushing.
  • addImpulse(x, y, z) applies an instantaneous impulse.
  • addTorque(x, y, z) applies a rotational force for the next physics step, the same way.

All three also work on soft bodies, which need much larger numbers than their size suggests — see Soft bodies.

To read or overwrite motion directly, use getLinearVelocity(), setLinearVelocity(x, y, z), getAngularVelocity(), and setAngularVelocity(x, y, z).

Respawning. setPosition moves a body but leaves its momentum alone, so a respawned ball or car arrives still travelling and leaves again. Use resetPhysicsState(x, y, z) instead. It places the object, zeroes its linear and angular velocity, clears a vehicle's driver input, stops its wheels, tracks and engine, and wakes the body, all in one step. Pass a quaternion as four more arguments, resetPhysicsState(x, y, z, qx, qy, qz, qw), to set the rotation at the same time.

None of the force or velocity calls affect a character, which has no rigid body. Push a character by changing its velocity with setCharacterVelocity — see Characters.

Kinematic bodies and moving platforms

An object's Motion is Dynamic (moved by gravity, forces and collisions), Static (never moves) or Kinematic (scripted) (motion: "kinematic"): moved only by its script, never by gravity or by anything it hits. Kinematic is available on a cube, sphere, cylinder, capsule or mesh; a mesh whose collision is the triangle mesh stays static whatever its Motion says, so give a moving mesh a convex or primitive collider. Use it for moving platforms, lifts, doors and sweepers. A trigger volume is always kinematic, whatever its Motion says.

Move one with gameObject.moveKinematic(position, rotation, deltaTime), called every frame from update(deltaTime) with the deltaTime it was given. position is a world-space {x=, y=, z=} target and rotation a {x=, y=, z=, w=} quaternion; pass nil, or leave it out as moveKinematic(position, deltaTime), to keep the current rotation. The body reaches the target over the frame at the velocity that takes, so it pushes dynamic bodies, lifts and lowers a character standing on it, and fires triggers as it passes. A frame with no call stops it. The call returns false and does nothing on an object that is not kinematic, or on one a bone socket is carrying.

local origin
local time = 0

function init()
  origin = gameObject.getPosition()
end

function update(deltaTime)
  time = time + deltaTime
  local target = { x = origin.x + math.sin(time) * 4, y = origin.y, z = origin.z }
  gameObject.moveKinematic(target, nil, deltaTime)
end

setPosition and setRotation still work on a kinematic body, but they teleport it. A teleported body has no velocity, so a rider is left behind and contacts see it standing still: use them to snap or reset a platform, and moveKinematic for travel. Stop restores the authored pose. A character on a platform is lifted and lowered automatically but is not carried sideways; its control script adds the ground's velocity, as described in Characters. The same ground velocity carries a rider round a turntable or spinning disc, because it is the motion of the point the character stands on. The rider's facing does not turn with it unless the control script adds getGroundAngularVelocity().

Do not build a platform from a dynamic body with Gravity Factor 0: anything that lands on it knocks it away. In a multiplayer room, a kinematic platform's script must run on the room server (multiplayer.scriptRole: "authority"); see Multiplayer games.

Mass

The Mass field on a dynamic body is blank by default and reads Auto. An object with no mass set is weighed from its collider at a density of 1000 kg/m³ — the density of water — so a 1×1×1 m cube comes out at 1000 kg, and a sphere of radius 1 at about 4189 kg. Because the weight follows the collider, resizing an object re-weighs it.

Enter a number to override that and pin the mass in kilograms; clear the field to go back to the derived weight. Mass applies only to dynamic bodies, and it is what makes addForce, addImpulse, and addTorque feel heavy or light — an impulse that sends a 10 kg crate flying will barely disturb a default-weight cube. Characters have their own Mass field, used by the character controller, and vehicles use chassis mass instead. A soft body ignores the field entirely — its mass is its vertex count, which is usually far higher than you would guess; see Soft bodies.

Other rigid-body settings

The same inspector section as Mass carries the rest of a dynamic body's settings. Like Mass, it appears only on a dynamic cube, sphere, cylinder, capsule, or mesh that is not a trigger or a soft body.

  • Friction — blank uses the default of 0.2.
  • Restitution — bounciness from 0 to 1; blank is 0, no bounce.
  • Gravity Factor — multiplies the scene's gravity for this body. 1 is normal, 0 floats, and a negative value makes it rise.
  • Center of Mass Offset — moves the balance point in the object's local space, scaled with the object. A lower Y makes an object harder to tip over.
  • Lock to 2D Plane (XY) — the body can only move in X and Y and only rotate about Z, for side-scrollers and pinball tables.
  • Continuous Collision (CCD) — for small, fast bodies such as balls, thrown props and projectiles. See Fast bodies and continuous collision.
  • Linear Damping, Angular Damping and Max Spin (rad/s) — how quickly the body slows down and stops spinning on its own, and how fast it may spin. See Damping and spin.

Where two bodies touch, their frictions are combined as the square root of the product and their restitutions by taking the larger, so a bouncy ball still bounces off a floor with no restitution, and either surface at zero friction makes the contact frictionless. A triangle-mesh model's per-surface friction and restitution replace the body's own on that surface — see Assets, materials, and shaders.

Damping and spin

A dynamic cube, sphere, cylinder, capsule or mesh slows down on its own by its damping, set in the Rigid Body section under Gravity Factor. Linear Damping (linearDamping) and Angular Damping (angularDamping) are the share of its speed and of its spin it loses per second, and Max Spin (rad/s) (maxAngularVelocity) is the fastest it may spin. A blank field uses the physics engine's default, 0.05, 0.05 and about 47.1 rad/s, and clearing a field goes back to it. A rolling-ball vehicle wants an Angular Damping of about 4, so the ball stops spinning soon after nothing drives it. Kinematic and static bodies always use the defaults.

The damping is applied inside every physics step, so it behaves the same at any frame rate. Do not damp a body from Lua by scaling its velocity in update, such as setAngularVelocity(v.x * 0.9, v.y * 0.9, v.z * 0.9) every frame: how much that takes off per second depends on how many frames run. Set the field instead; there is no Lua call for it.

Radial gravity (planets)

scene.setRadialGravity({center = {x=0, y=0, z=0}, strength = 9.81}) pulls every dynamic body toward a point. The scene's gravity still applies, and each body is given the difference as a force every step, scaled by its gravity factor. A body resting on a planet can go to sleep: a sleeping body is left alone, and changing or clearing the source wakes every dynamic body once.

  • falloff = "inverseSquare" keeps strength up to radius (the planet's surface) and weakens it as (radius/distance)² beyond; "none", the default, is constant.
  • maxDistance limits its reach. Beyond it the scene's own gravity applies.
  • One source per scene: calling it again replaces the first, and scene.clearRadialGravity() removes it. scene.getRadialGravity() returns the current settings, or nil, and scene.getGravityAt(x, y, z) the gravity acting at a point — the radial pull where it reaches, the scene's gravity elsewhere.
  • alignCharacters = false keeps characters on world up while bodies still fall toward the centre; the default is true. radius defaults to 1 and strength to 9.81; a negative strength is refused.
  • Vehicles' wheel suspension, ragdolls, soft bodies, particles and water buoyancy still use the scene's gravity.

Characters walk on it too; see Characters. Single player only: the call raises an error in a multiplayer room.

Fast bodies and continuous collision

Physics moves a body in steps. A body that travels farther than a thin wall's thickness in one step can pass straight through it. Turn on Continuous Collision (CCD) in the object's Rigid Body panel (motionQuality: "linearCast" over MCP) and the engine sweeps the body's shape along its path each step instead, so it stops at the wall. Use it on small, fast bodies such as balls, thrown props and projectiles; each body with it costs a shape cast per step, so leave it off for slow and large ones. A script can switch it for the rest of a run with setMotionQuality("linearCast"), for example just before a throw, and Stop restores the authored setting.

Slow motion. scene.setTimeScale slows or speeds up the physics with everything else (see Time scale and slow motion). In slow motion each frame's collision steps only get shorter. Fast-forward splits a frame into more of them, so no collision step is longer than 1/120 s. At a scale of 0 the physics does not step at all and every body is frozen with its velocity, which it keeps when time starts again.

Grabbing and carrying

gameObject.grab(options) holds a dynamic body on a spring: a point on it is pulled toward a target you move every frame. The spring is a constraint solved inside the physics step, so the hold behaves the same at any frame rate, and maxForce caps the pull so a heavy or wedged prop stays put rather than being dragged through a wall. Grab off-centre, at a raycast hit's point, and the prop swings from that point; pass holdRotation = true to keep it level. Releasing keeps the velocity it was carried at, so a quick flick throws it. The options are in the Lua object API. This gravity gun picks up what the aim hits on an authored grab action, holds it 3 m ahead, and throws it on primary fire:

local held = nil

function update(deltaTime)
  local aim = gameObject.getForward()
  local eye = gameObject.getPosition()
  if held == nil and input.actions.grab then
    local hit = gameObject.raycast(aim, 6)[1]
    local prop = hit and gameObject.getObject(hit.shape)
    if prop then
      held = prop.grab({anchor = hit.point, frequency = 6, maxForce = 2000, ignoreGravity = true})
    end
  end
  if held ~= nil and held.isActive() then
    held.setTarget(eye.x + aim.x * 3, eye.y + 1.4 + aim.y * 3, eye.z + aim.z * 3)
    if input.primaryFire then
      local prop = gameObject.getObject(held.objectId)
      held.release()
      prop.setMotionQuality("linearCast")
      prop.addImpulse(aim.x * 400, aim.y * 400, aim.z * 400)
      held = nil
    end
  end
end

Grabbing an object that is already held replaces its grab, and destroying the object or stopping the run releases it. In a multiplayer room only the authority may grab; see Carry and throw props.

On a ragdoll, add bone = "mixamorig:RightHand" to hold one bone. Each bone has its own grab, so two hands can hold two limbs. A grab does nothing while the ragdoll is animated.

Collision callbacks

Call registerForCollisions() from init() before using collision or trigger callbacks. Call deregisterForCollisions() to stop receiving them again, for example when a script disables itself.

function init()
    gameObject.registerForCollisions()
end

function onCollisionEnter(other)
    print("Hit " .. other.id)
    print("Normal Y: " .. other.normal.y)
end

function onCollisionExit(other)
    print("Left " .. other.id)
end

In onCollisionEnter and onTriggerEnter, other carries id, the other object's position and rotation, normal, contactPoint, contactDepth, and isTrigger. normal points away from the other object, toward this one. onCollisionExit and onTriggerExit get only id, position, and rotation, because there is no contact left to describe. Treat it as callback-local data; copy plain numbers if you need them later.

How hard things meet. onCollisionEnter, onTriggerEnter and onCollisionStay also give other these fields, for impact sounds, damage and knockback:

FieldMeaning
approachSpeedHow fast the two are closing along normal, in m/s; positive while closing
tangentialSpeedHow fast they slide across each other, in m/s. Zero for clean rolling
relativeVelocityThe other object's velocity at the contact point relative to this one's, including spin, as {x, y, z}
estimatedImpulseAn estimate of the impulse along the normal, in N·s
estimatedTangentialImpulseAn estimate of the impulse that stops the slide, in N·s, capped by friction

They are read before the physics solver applies the collision, so approachSpeed is how fast the two arrived, not how fast they bounced. The two impulses are estimates: the physics engine does not report the impulse it applied, so they are worked out from mass, approach speed, restitution and friction. They measure the impact, not the force holding a resting object up. The impulses are nil on triggers, on kinematic-against-static contacts and on any contact with a character; a character's contacts carry the three speeds, measured after the character moved that frame. All five are nil when a character enters a trigger, so guard with or 0.

onCollisionStay(other) is optional. It arrives once a frame for each solid contact that keeps touching, with the same other as onCollisionEnter, and stops once both bodies sleep. Only a script that defines it is asked, so other objects pay nothing. It has no threshold of its own; filter on the speeds. This plays impacts that scale with how hard things hit and a scrape loop while they slide:

local IMPACT_SOUND = "<impact asset id>"
local SCRAPE_SOUND = "<looping scrape asset id>"
local scrapeId = nil
local scrapeLevel = 0

function init()
    gameObject.registerForCollisions()
end

function onCollisionEnter(other)
    local speed = other.approachSpeed or 0
    if speed > 0.5 then
        gameObject.playSound(IMPACT_SOUND, { volume = math.min(1, speed / 8) })
    end
end

function onCollisionStay(other)
    scrapeLevel = math.max(scrapeLevel, math.min(1, (other.tangentialSpeed or 0) / 5))
end

function update(deltaTime)
    if scrapeLevel > 0.05 and not scrapeId then
        scrapeId = gameObject.playSound(SCRAPE_SOUND, { loop = true, volume = 0 })
    end
    if scrapeId then
        if scrapeLevel > 0.05 then
            gameObject.setSoundVolume(scrapeId, scrapeLevel, 0.05)
        else
            gameObject.stopSound(scrapeId, 0.1)
            scrapeId = nil
        end
    end
    scrapeLevel = 0
end

Characters report their contacts. When a character touches a body — a ball thrown at it, a crate it walks into, the floor it lands on — both sides get onCollisionEnter, and onCollisionExit once Jolt stops listing the pair, provided each side has called registerForCollisions(). A ball resting against a character stays entered rather than entering and leaving every frame, and two characters touching count as one contact. other.normal follows the same rule as any other contact. Until early October 2026 neither side heard about a character contact, so a script that compares a ball's position against each character's capsule to detect a hit can use onCollisionEnter instead.

Characters and light bodies. A character is not a rigid body and does not take part in mass-based collision. A dynamic body lighter than a tenth of the character's mass is treated as light. The character's movement pushes it, with up to the character's Max Strength, but the light body's own motion and spin never move the character: it cannot shove the character, carry it or launch it, and walk-stairs never steps onto it. Heavier dynamic bodies can still push a character and be stood on. See Characters.

other is a plain data table, not a gameObject. It carries the fields above and nothing else — it has no methods on it. other.setPosition(...), other.setVar(...) and the rest are all nil, and calling one raises an error inside the callback. The handler stops at that point, so from the outside the collision looks exactly like one that never fired: the other object simply does not move. To act on what you hit, resolve it to a real object first with gameObject.getObject(other.id).

function onTriggerEnter(other)
    local entered = gameObject.getObject(other.id)
    if entered then
        entered.setPosition(0, 5, 0)
    end
end

Errors raised inside a callback are reported to the browser console, and physics_run_simulation returns them in script_errors. Check that list first whenever a contact is recorded but nothing moved.

Trigger volumes

Enable Trigger Volume on a cube, sphere, cylinder, or capsule. Triggers do not block motion and invoke onTriggerEnter(other) and onTriggerExit(other). They are simulated as kinematic moving-layer sensors so they can detect static bodies and characters. A soft body cannot be a trigger volume — see below.

A trigger starts the run asleep and costs nothing until something moves into it or it is moved itself, so decorative triggers in a large scene are free. A body or character that moves into it is reported as before. One case is not: a sleeping body put inside a sleeping trigger by setting its position is not reported until one of them moves. Move the trigger, or give the body a velocity, if a script relies on that.

If a script registered for collisions defines no onTriggerEnter or onTriggerExit, trigger contacts are delivered to onCollisionEnter and onCollisionExit instead, with other.isTrigger set to true. Define the trigger handlers whenever you want to tell the two apart.

Visual-only objects

A cube, sphere, cylinder or capsule normally has a collider. Turn on Visual Only in its properties, or set collisionType: "none" through MCP, and it is drawn with no collider at all: players, objects, raycasts, shots and triggers pass through it, and it is left out of the navigation mesh. A mesh does the same with its collision set to None. A visual-only object still moves with its parent and with its own script.

A cube, sphere, cylinder or capsule whose motion is "rig" is visual-only too, the same as collisionType: "none": rig means no body of its own. Before 17 October 2026 such a primitive was simulated as a dynamic body, so a pool of effect spheres parked in one spot fell as a pile of overlapping bodies all game. If a primitive on rig should fall or be pushed, set its Motion to Dynamic; turning off Visual Only on it in the editor does that.

Use it for decoration attached to something that moves, above all to a player. A first-person weapon built from primitives and attached to the camera sits inside the player's capsule, and solid parts there push the player sideways every frame, with no input. Do not use Trigger Volume (isSensor) for decoration: a trigger still fires onTriggerEnter and still stops raycasts. On a primitive, "none" is the only collisionType accepted, and a soft body cannot be visual-only.

Invisible colliders

The opposite of visual-only is a collider nobody sees: an invisible wall, a floor under a backdrop, a barrier at the edge of the map. Turn off Visible in Game on a cube, sphere, cylinder, capsule or mesh, or send visible: false through MCP. The object keeps its collider, its triggers, raycasts and its place in the navigation mesh, but Preview and published games do not draw it and it casts no shadow. Anything parented to it is still drawn. In the editor a hidden primitive is drawn as an orange wireframe so you can still select it; a hidden mesh is drawn normally there.

Use this rather than a transparent material. To keep an object drawn but drop its shadow, turn off Casts Shadow (castsShadow), which cubes, spheres, cylinders and capsules have as well as meshes. A script can hide any 3D object for the rest of a run with setVisible(false), and show one authored hidden with setVisible(true); the collider is unchanged either way, and stopping a run in the editor puts the authored visibility back; see the gameObject API reference. A scene script can also create an invisible collider at runtime with scene.createObject("cube", { visible = false, ... }), and castsShadow = false drops a runtime object's shadow the same way; see Runtime objects.

Compound bodies

An object whose children include a collider gets no collider of its own; each of those children gets its own body instead. For a chair built from a seat and four legs, that means five separate bodies that fall apart.

Children that collide with nothing are decoration and leave their parent's body alone: a visual-only object (a mesh with collision set to None, or a primitive with Visual Only on), a light, a camera, a constraint, or a GUI element. A ball with a seams mesh under it still falls, bounces and takes impulses, and the seams ride along with it. An empty counts by what is under it. Before 3 October 2026 any child at all took the parent's collider away, so a decorated dynamic object hung where it was placed and ignored addImpulse without an error. A script that pushes such a parent still moves nothing, because the parent has no body of its own: push the child bodies, or turn on Compound Children.

Turn on Compound Children on a cube, sphere, cylinder, or capsule parent to combine its direct cube, sphere, cylinder, and capsule children into one rigid body. The children stay where you placed them and keep rendering normally, but they no longer get bodies of their own, and the parent's own shape is no longer part of the collider — the children are the collider. Scaling the parent scales the whole compound. If the parent has no eligible children it falls back to its own shape. Soft bodies cannot be a compound parent or a compound child.

Collision groups

Sometimes two objects should pass through each other while still colliding with everything else — a vehicle's wheels against its own chassis, or the neighbouring limbs of a ragdoll, which would otherwise jitter against each other at every joint.

By default an object has no collision group and collides with everything on ordinary layer rules. Give two or more objects the same Collision Group ID and they stop consulting the layers against each other and consult that group's filter table instead.

The table lives on the scene, not the object. Edit it under Collision Groups in Scene Settings: + Group adds a group, and + Pair adds a disabled pair to it. Each group in the scene's collision-group configuration carries:

  • groupId — the number objects refer to.
  • subGroupCount — how many subgroups the group has (Sub-Group Capacity in Scene Settings, 16 by default, at most 256).
  • disabledPairs — the pairs of subgroups that do not collide, as [a, b].

Each object then picks its own Sub-Group ID within the group, defaulting to 0. A pair of subgroups listed in disabledPairs passes through; any pair not listed still collides normally, so the table is a list of exceptions rather than a whitelist. Giving every part its own subgroup and listing no pairs changes nothing.

A body with a group still collides normally with every body that has no group at all — filtering only applies between two bodies sharing a groupId. Set the per-object ids in the inspector or through scene_objects_update (collisionGroupId, collisionSubGroupId), and the group table in Scene Settings or through scenes_update, whose collision_groups entries take group_id, sub_group_count, and disabled_pairs.

Constraint attachment points and offsets

A constraint object joins Body A and Body B where it stands. bodyAOffset and bodyBOffset (hinge, point, swingTwist, slider, sixDOF and cone; {x, y, z}) are usually best left out: place the constraint object exactly at the joint, and both bodies attach there. An offset is measured from the constraint object's world position, not from the body's centre. When the run starts, body A attaches at constraint position + (body A's rotation × bodyAOffset), and body B likewise. The constraint's own rotation and the body's scale do not apply. The joint then holds the two attachment points together, so any difference between them is a gap it closes by pulling the bodies together at the start of the run. A slider keeps the part along its axis as its starting travel. Fixed, distance, pulley and path constraints ignore both offsets.

For example, a point joint at (0, 1.31, -5) links a torso centred at y 1.65 and a pelvis centred at y 1.17. With no offsets, both attach at y 1.31 and stay 0.48 apart. Entering the centre-to-joint vectors instead (bodyAOffset {y: -0.34}, bodyBOffset {y: 0.14}) attaches the torso at y 0.97 and the pelvis at y 1.45, and pulling those points together leaves the centres 0.96 apart, double the intended gap.

To join two bodies, move the constraint object to where they meet; do not try to reach the joint from each body with offsets.

The diamond that marks a constraint object, and the lines to its bodies, are editor-only. Preview, a published game, a run through a scene camera and a scene-camera screenshot do not draw them.

Conveyor surfaces

Conveyor Velocity gives a body's surface a tangential velocity in units per second, so anything resting on it is carried along while the body itself stays exactly where it is. It drives conveyor belts, moving walkways, and treadmills without moving or duplicating any geometry.

The velocity is in the body's local space and is rotated into world space by the body's current orientation at each contact. Rotating the belt therefore turns the direction it carries things, and a belt on a slope pushes along the slope rather than horizontally. The default is zero, which has no effect.

Because this is a surface property applied at the contact, nothing is actually in motion: a static body works as a conveyor, and the carried object keeps its own mass, friction, and gravity. Friction is what transfers the motion, so a very low-friction material on either side will slip rather than ride.

Soft bodies

Soft Body is a switch on an ordinary shape, not a separate kind of object. Turn it on for a cube, sphere, cylinder, capsule, or mesh and that object is simulated with Jolt's soft-body solver: it deforms under collision and gravity instead of moving as one rigid shape. Cloth is the exception and remains its own object type, because it is an open pinned sheet with no rigid equivalent to switch.

The switch carries no dimensions of its own. A soft cylinder deforms the cylinder's own Radius and Half Height, so resizing the shape resizes the body, and turning the switch back off leaves the same rigid shape at the same size. Turning it on forces the object dynamic and clears Trigger Volume and Compound Children: Jolt has no static or kinematic soft body, no soft sensor, and no soft compound shape.

Soft bodies cost the most. They are the costliest physics there is. A soft body costs its simulated vertex count multiplied by its Solver iterations on every physics step while it is awake; a rigid body costs next to nothing beside it. Seven soft balls of 146 vertices at 9 iterations can take nearly all of a scene's physics time. A soft body that is still goes to sleep and then costs nothing, but one inside a trigger volume never sleeps, because a trigger keeps what is inside it awake.

  • For a jelly ball, Radial segments 12 and Vertical segments 8 (segmentsPhi and segmentsTheta), 74 vertices, look the same as the defaults of 20 and 10, 162 vertices: pressure already holds a ball's shape.
  • Keep Solver iterations at 5 or fewer. Raising iterations or segments does not make a ball look better.
  • Use a Bend constraint of distance (the default) or none rather than dihedral.
  • Use one or a few soft bodies per scene, not many, and keep them out of trigger volumes.

The publish check warns with soft_body_cost when a scene's soft bodies add up to more than 4,000 vertices × iterations; five default spheres are just over it. The warning names the scene and counts its soft bodies and their vertices, and an MCP client also gets the costliest object's name in heaviest_object_name. See Publish and test a game.

Pressure and stiffness. Sphere, cylinder, capsule, and mesh are hollow shells that keep their form because Pressure inflates them — with too little, they fold flat under anything resting on them. The cube is different: it is a solid lattice held up by tetrahedral volume constraints, so it wants very little pressure and is tuned with Volume Compliance instead. Smaller compliance values are stiffer.

Vertex Radius is a collision margin around every simulated vertex, which makes a body slightly larger than its authored dimensions. Objects stacked at exactly their own height will therefore overlap and shove each other apart; leave a small gap, or reduce the radius.

Soft meshes. A soft mesh is rebuilt as a simplified shell of the model — its triangles are welded and decimated down to the Vertex Budget, and that shell is both the simulated body and what you see. It loses the source asset's materials, UVs, and any animation, and renders in the object's own material. A model that is not watertight has no interior for pressure to act on, so it is simulated double-sided with pressure ignored, like cloth.

Soft bodies are created and configured in the editor, or through the MCP soft_bodies_create and soft_bodies_update tools.

Pushing one from Lua. addForce, addImpulse and addTorque all work on a soft body, exactly as they do on a rigid one. (There is no applyImpulse, on any kind of object — the method is addImpulse.) What changes is the magnitude you need.

A soft body's mass is its vertex count. Every simulated vertex weighs 1 kg, so the default soft sphere is 162 vertices and therefore 162 kg — and raising Vertical segments or Radial segments for a smoother ball makes it heavier, not just denser-looking. The Mass field above does not apply to soft bodies at all; it is ignored. An impulse tuned against a rigid sphere will look like it did nothing. Multiply by the vertex count, or start around 500 and work down.

function onTriggerEnter(other)
    local ball = gameObject.getObjectByName("Jelly Ball")
    if ball then
        ball.addImpulse(800, 0, 0)  -- about 5 m/s on a 162-vertex sphere
    end
end

Use addImpulse for a one-off shove from a trigger, as above. addForce and addTorque are per-frame: like Jolt's own accumulators they are consumed by the next physics step and then cleared, so a single call from onTriggerEnter lasts one frame. To push for longer, call them from update(dt) while a flag you set in the callback is still true.

A pinned cloth's pinned vertices are anchors: they do not move, and they carry none of the push, so the free part of the sheet takes all of it.

Water

A water object is a box of fluid. Its top face is the surface and the whole box is the volume. Every dynamic body inside it is pushed up by buoyancy, slowed by drag, and carried by the current, every step. The water blocks nothing, and it stays where you placed it unless a script moves it.

  • Buoyancy (default 1.1) — 1 is roughly neutral when fully submerged; above 1 floats, below 1 sinks.
  • Linear drag (default 0.3) — slows movement relative to the current.
  • Angular drag (default 0.05) — slows rotation.
  • Current velocity (default zero) — a world-space velocity the water carries things along at.

The two drags act only on what floats in the water; they are not a body's own damping. For a body that should slow down or stop spinning everywhere, set its damping. How much of a body is under the surface decides how hard it is pushed, so a heavy object still sinks until enough of it is submerged. Characters float and swim in water too — see Characters.

Raising and lowering the water. Water is simulated as a kinematic sensor, so a script on the water object can move it to raise or lower the surface, for a rising tide or a flooding room. Its Motion stays Static, the only value water takes. Call setPosition from update(deltaTime) with a small step each frame:

local TOP = 3      -- surface height to rise to, in metres above where it starts
local SPEED = 0.5  -- metres per second
local startY

function init()
    startY = gameObject.getPosition().y
end

function update(deltaTime)
    local p = gameObject.getPosition()
    if p.y < startY + TOP then
        gameObject.setPosition(p.x, math.min(p.y + SPEED * deltaTime, startY + TOP), p.z)
    end
end

A body resting in still water goes to sleep like any other. When the water moves, resizes or rotates, or its buoyancy, drag or current changes, every sleeping body that is in it, or was in it, is woken. A crate asleep on the bottom therefore floats up as the water rises over it, and floating bodies fall when the water drops away from them. You do not need to nudge them with addForce to keep them awake. In a multiplayer room, the script that moves the water must be an authority script (multiplayer.scriptRole: "authority"); see Multiplayer games.

Spatial queries

  • raycast(direction, maxDistance, options)
  • sphereQuery(radius)
  • boxQuery(halfExtents)

All three start at the calling object's position. raycast's direction is a world-space vector; it is not rotated by the object, and it is normalized for you. It returns a list of hits sorted nearest first, empty on a miss, and each hit is a table {shape, point, distance, fraction}: shape is the id of the object hit, and fraction is distance / maxDistance. There is no surface normal. sphereQuery and boxQuery return a list of object ids. boxQuery's box is aligned to the world axes, not to the object.

A ray stops at the nearest thing in its way. The list can hold more than one hit, but never anything behind that first object, so skipping a hit in the script does not reveal what is behind it. Say what the ray should pass through in the optional third argument instead:

  • ignore: objects or ids to pass through, as a list or a single one.
  • ignoreSensors = true: pass through trigger volumes, which are hit by default.
  • ignoreSelf = false: hit the calling object too. It is ignored by default, because a ray that starts inside an object always hits it at distance 0.

Characters are found by their capsule. A shot from a first-person camera, which sits inside the player's capsule, passes the player in ignore:

local player = gameObject.getObjectByName("Player 1")
local hits = gameObject.raycast(gameObject.getForward(), 100, {
    ignore = { player },
    ignoreSensors = true,
})
if #hits > 0 then
    print("Hit " .. hits[1].shape .. " at " .. hits[1].distance)
end

Before 9 October 2026 there were no options and the calling object was included. sphereQuery and boxQuery take no options and still include the calling object and trigger volumes, so skip those by id.

See Cross-object interactions for a complete example that finds nearby rigid bodies, resolves their object APIs, and applies radial impulses.