gameObject API reference
Signatures for transforms, physics, lookup, audio, GUI, hierarchy, vehicles, and constraints.
Identity, lookup, and variables
| Signature | Result |
|---|---|
gameObject.id | Current object UUID |
destroy() | Removes this object from the running simulation and returns true; false when the simulation is stopped or the object is already being removed (see Cross-object interactions) |
getVar(name) | number, string, boolean, object API, or nil |
setVar(name, value) | Sets a number, string, or boolean variable. It cannot set an object reference, and it does nothing on an object that has no variables at all, so define at least one on the object in the inspector first |
getObject(uuid) | Object API or nil |
getObjectByName(name) | Exact-name match or nil |
getObjectsByNamePrefix(prefix) | Array of object APIs |
getObjectsByType(type) | Array of object APIs |
getObjectsByTag(tag) | Live object APIs in the current scene with this exact tag; an empty list when none match |
getTags() | A fresh list of this object's authored tags |
hasTag(tag) | Whether this object carries the exact tag |
An object API is a Lua table (type() is "table"; before 17 October 2026 it was "userdata"), and the same object comes back as the same table each time. Calls on it are cheap, but a lookup is not free: find the objects a script uses once in init() and keep them, rather than looking them up every frame. In Preview and published games an object a script has looked up is also drawn on its own for the rest of the play instead of in a batch with matching scenery, so in a scene script avoid sweeping the scenery with getObjectsByType or a broad getObjectsByNamePrefix. See "Engine values are Lua tables" in Lua scripting overview.
Object tags
Enter comma-separated Tags in the inspector to group objects independently of names and types. Each object supports up to 16 unique tags, each 1–32 characters, starting with a lowercase letter and continuing with lowercase letters, digits, underscores or hyphens. Matching is case sensitive: enemy and Enemy are different queries.
Use gameObject.getObjectsByTag("enemy") from an object script or scene.getObjectsByTag("enemy") from a scene script. Existing scene and multiplayer role boundaries apply. Tags are read-only during play; editing the list returned by getTags() does not change the object. Runtime-created objects may receive tags through creation options, and clones inherit them. See Scene scripts and storage.
Transforms and hierarchy
getPosition(), setPosition(x,y,z), getRotation(), setRotation(x,y,z,w), rotate(x,y,z), getParent(), getChildren(), setParent(parentIdOrNil), getWorldPosition(), getWorldRotation(), getWorldScale(), getLocalPosition(), getLocalRotation(), getLocalScale(), setScale(x,y,z), getForward(), getRight(), isRoot().
setScale(x,y,z) changes how the object is drawn for the rest of the run, and returns false for a component that is not a finite number. It is visual only: the collider keeps the size it was built with, so collisions, triggers, raycasts and queries still see the authored shape. Use it for effects such as a stretching rope segment, a pulsing pickup or a squash on landing, never to make something physically bigger or smaller. getLocalScale() and getWorldScale() report the new scale, and children are drawn scaled and placed with it, so it is simplest on an object with no children. Stop restores the authored scale. It is not replicated: in a multiplayer room call it from a camera, GUI or presentation script, and it changes only that browser's view.
getForward() and getRight()
Both return world-space unit vectors. For an ordinary object they are derived from its world rotation, where local +Z is forward and local +X is right — the same convention characters and vehicles face along.
A camera is the exception. On a camera, getForward() returns the direction it is actually rendering and getRight() its screen-right. Three.js cameras look down their own local -Z while the rest of Airogel faces +Z, so deriving a camera's forward from its rotation the ordinary way would hand you the opposite of what the player sees; these two calls reconcile that for you.
That is what makes camera-relative movement work: read the active camera's forward and right, flatten them to the XZ plane if you do not want pitch, and use those as your movement axes instead of fixed world X/Z.
local camera = scene.getActiveCamera()
local forward = camera.getForward()
local right = camera.getRight()
getPosition() and getRotation() on a camera likewise return the pose it is rendering from, including a first_person or third_person camera that the engine is moving to follow its target, so a script reading the camera during update() sees what the player sees.
In a multiplayer room, a presentation script (a camera, GUI or other presentation script) that reads another player's character or vehicle, a replicated prop, or the local player's own character gets where this screen draws it. getPosition(), getRotation(), getWorldPosition(), getWorldRotation(), getForward() and getRight() all return that drawn pose. The physics pose of another player jumps with each server frame and runs ahead of where the player is drawn, so a spectator or follow camera aimed at it shook. Authority scripts and the local player's predicted control script still read the physics pose. See Build and test a multiplayer game.
Transform tweens
tween.to(object, options) is a global helper, not a gameObject method. Pass gameObject for this object, gameObject.getObjectByName("Door") from an object script, or scene.getObjectByName("Door") from a scene script. It returns a handle with handle:cancel(). Resolve the handle before scheduling and check it exists.
-- Scene script: Door must be static or kinematic.
local opening
function init()
local door = scene.getObjectByName("Door")
if not door then return end
opening = tween.to(door, {
position = { y = 4 },
rotation = { x = 0, y = 0.70710678, z = 0, w = 0.70710678 },
duration = 1,
easing = "outQuad",
onComplete = function() print("Door open") end,
})
end
| Option | Meaning |
|---|---|
position | World-space target {x, y, z}. Omitted axes keep their values from scheduling time. |
rotation | Complete, finite, non-zero quaternion {x, y, z, w}. It is normalized and interpolated along the shortest arc. |
scale | Local visual target {x, y, z}; omitted axes keep their starting values. The collider keeps its authored size, as with setScale. |
duration | Required finite, non-negative simulation seconds. |
easing | Optional fixed easing name; defaults to "linear". |
onComplete | Optional function, called once after submitting the final transform sample. It does not run after interruption, cancellation or target destruction. |
At least one of position, rotation and scale is required. Targets are captured when scheduled; later edits to the options table do not change them. Use a scripted camera for transform movement: attaching a script to a camera disables its built-in controller, which would otherwise compete with the tween.
getMotionType() reports the object's live physics mode: "none" (no body), "static", "kinematic", "dynamic", "character" or "soft"; it returns nil after destruction. Transform tweens accept none, static and kinematic. Kinematic position and rotation use moveKinematic with that step's delta, preserving the velocity that carries riders. Static and bodyless objects use the transform setters. Dynamic bodies, characters and soft bodies are refused, including for scale-only transform tweens; use their physics movement APIs, or tween.value with a permitted visual setter for a purely visual effect.
A destroyed target cancels silently. A target that changes to an unsupported physics mode, or a refused kinematic move (for example, a bone socket owns its movement), cancels with a script error. See Physics, collisions and triggers for moving-platform setup.
The fixed easing names are linear, inQuad, outQuad, inOutQuad, inCubic, outCubic, inOutCubic, inBack, outBack and inOutBack. Back curves overshoot; use a curve without overshoot when that would cross a wall or take a visual value outside its useful range. Custom curve functions are not supported.
Both tween.to and tween.value(from, to, duration, easing, callback) return cancellable handles. Pass nil as the value tween's easing for linear interpolation. Cancellation is idempotent and keeps the last sample. tween.cancelAll() affects only the calling script.
Within one script, a new transform tween replaces older overlapping channels on the same object. Position, rotation and scale are separate channels; individual axes are not. A new position tween replaces the whole older position channel, even if one targets X and the other Y. Unrelated channels continue, but an interrupted tween's onComplete is suppressed. Different scripts should not drive the same property. Generic value tweens have no automatic overlap detection.
See Simulation-time tweens for a complete object-script example, scheduling order, limits and cleanup. Every setter called by a tween retains its normal multiplayer permissions: scale and GUI/camera effects are presentation work; see Tweens and prediction.
Physics and queries
addForce(x,y,z), addImpulse(x,y,z), addTorque(x,y,z), getLinearVelocity(), setLinearVelocity(x,y,z), getAngularVelocity(), setAngularVelocity(x,y,z), resetPhysicsState(x,y,z,qx?,qy?,qz?,qw?), moveKinematic(position,rotation?,deltaTime), grab(options), setMotionQuality(quality), registerForCollisions(), deregisterForCollisions(), raycast(direction,maxDistance,options?), sphereQuery(radius), boxQuery(halfExtents).
setPosition() deliberately preserves momentum. Use resetPhysicsState() for respawn or recovery: it teleports, applies the optional rotation, clears linear and angular velocity and vehicle driver input, stops a vehicle's drivetrain (wheel spin, track speed, and the engine back to idle in neutral), then wakes the body.
moveKinematic(position, rotation, deltaTime) moves an object whose motion is Kinematic (scripted) to a world-space target over this frame, at the velocity that takes, so it pushes bodies and carries characters standing on it. Call it every frame from update(deltaTime); rotation may be nil or left out. It returns false on an object that is not kinematic. See Kinematic bodies and moving platforms.
grab(options) holds a dynamic body on a spring, for a gravity gun or pick-up-and-carry. A point on it is pulled toward a target by a constraint solved inside the physics step, so the hold is the same at any frame rate. Every option is optional:
| Option | Meaning |
|---|---|
anchor | World-space point on the body to grab, such as a raycast hit's point. Default its centre of mass |
localAnchor | The same point as an offset from the object's origin, in its own space; wins over anchor |
target | Where the grab point is pulled. Default where it is |
frequency, damping | Spring frequency in Hz (default 4) and damping ratio (default 1) |
stiffness | Spring stiffness in N/m instead of frequency; damping is then N·s/m |
maxForce | Most force the spring applies, in newtons, so a heavy or wedged object stays put rather than being dragged through a wall. Default unlimited |
holdRotation, maxTorque | Also keep the orientation it had when grabbed, capped at maxTorque N·m. Without it, an object grabbed off-centre swings |
ignoreGravity | Turn its gravity off while held, so the spring does not sag |
It returns a handle, or nil for anything but a dynamic rigid body while the simulation runs. Call handle.setTarget(x, y, z) every frame; handle.release() lets go, and the object keeps the velocity it was carried at, which is how to throw. handle.getTarget() and handle.isActive() read it back. Grabbing an object again replaces its grab; destroying it or stopping the run releases it. In a multiplayer room only the authority may grab. See Grabbing and carrying.
setMotionQuality(quality) takes "linearCast" to turn on continuous collision detection for a moving body, so a small, fast one cannot pass through a thin wall between physics steps, or "discrete", the default, to turn it off. It lasts for the rest of the run, and Stop restores the object's authored setting. It returns false on a static body, a soft body or a character.
To make a body slow down or stop spinning on its own, set its Linear Damping, Angular Damping or Max Spin in the inspector rather than scaling setLinearVelocity or setAngularVelocity every frame, which takes off more per second the faster the frame rate. There is no Lua call for them; see Damping and spin.
On a soft body, push rather than assign. addForce, addImpulse and addTorque all work on one, but setLinearVelocity and setAngularVelocity do not: a soft body's velocity is recomputed from its vertices every step, so an assigned value is discarded by the next one and the object simply carries on as it was. The matching getters are fine — they read the body's real aggregate motion. Soft bodies also need far larger numbers than their size suggests, because their mass is their vertex count; see Physics, collisions, and triggers.
raycast(direction, maxDistance, options)
Returns an array of hits sorted nearest first. The ray stops at the nearest object in its way: the array can hold more than one hit, but never anything behind that object. On a miss it returns an empty array, never nil or false, so #hits == 0 is the miss check and if hits then is always true. A zero-length direction, a non-finite maxDistance, or a maxDistance of zero or less also return empty rather than raising.
Each hit is a table with exactly these four fields:
| Field | Value |
|---|---|
shape | UUID of the object that was hit. This is the id field — there is no id, objectId or bodyId on a hit. |
point | World-space contact point, as {x, y, z} |
distance | Metres from the ray origin |
fraction | Position along the ray, 0 to 1 of maxDistance |
There is no surface normal on a hit.
Behaviour worth knowing before you rely on it:
- The ray originates at the calling object's world position. To cast from a character's eye rather than its origin, resolve the camera and call
raycaston that handle instead. The camera sits inside the character's capsule, so pass the character inignore. directionis world-space and is not rotated by the calling object's transform. Passing{x=0, y=0, z=1}casts along world +Z, which is only "forward" for an unrotated object. For object-relative aiming, rotate the direction yourself, or passgetForward()— on a camera that is the direction the player is looking.directiondoes not need to be normalized; it is normalized for you.optionsis an optional table.ignorelists objects to pass through, as object handles or UUIDs, in a list or a single one.ignoreSensors = truepasses through trigger volumes, which are hit by default.ignoreSelf = falseincludes the calling object, which is ignored by default because a ray that starts inside it hits it at distance 0. These filter inside the query; skipping a hit in the script cannot reveal what is behind it, because nothing behind it was found. Example:gameObject.raycast(gameObject.getForward(), 100, { ignore = { player }, ignoreSensors = true }).- Before 9 October 2026 there were no options, and the results included the calling object.
sphereQuery(radius) and boxQuery(halfExtents) are centred on the calling object and return arrays of object UUIDs rather than hit tables. They also include the calling object when it has a collider.
Characters and animation
isOnGround(), getGroundInfo(), getCharacterVelocity(), setCharacterVelocity(x,y,z), jump(), setCrouched(crouched), isCrouched(), isInWater(), getWaterSubmersion(), getWalkSpeed(), getRunSpeed(), plus the animation API.
getGroundInfo() bundles the common ground-state fields into one call:
| Field | Value |
|---|---|
objectId | UUID of the object the character is standing on, or nil when it is not on ground it can stand on |
objectName | That object's name, or nil |
slopeAngle | Angle of the surface it is touching, in degrees |
isTooSteep | True when that surface is steeper than the character can stand on |
velocity | Velocity of the ground, as {x, y, z}, so a character can ride a moving platform |
normal | Surface normal as {x, y, z}, or nil when nothing is touched |
The same data is also available piecemeal via getGroundNormal(), getGroundVelocity(), getGroundAngularVelocity() (the spin of what the character stands on, in radians per second about world axes; zero in the air), getGroundObjectId(), getGroundObject(), getSlopeAngle(), and isSlopeTooSteep(). getUp() returns the character's current up vector (usually {x=0, y=1, z=0}).
getWaterSubmersion() returns how much of the character is under water, from 0 (dry) to 1 (fully submerged); isInWater() is true whenever it is above 0. setCrouched(crouched) returns false when the collider could not change — most often when standing up under something too low — and the character stays as it was, so call it again on a later frame.
getWalkSpeed() and getRunSpeed() return the character's Walk Speed and Run Speed inspector fields in metres per second, or nil on anything but a character. The engine never moves a character by them; they are there for a controller script to read, so speed can be tuned per character without editing the script. jump() does nothing unless the character is on ground it can stand on, except in water, where it swims upward at half the character's Jump Speed.
Played by a bot (characters and vehicles)
setBotBrain(name)hands the object to a bot brain from the next step:"wander","roam","script"or"idle". Its own control script then reads that brain's input asinputinstead of the player's.setBotBrain(nil)hands it back to the player. Returnstrue, orfalseand changes nothing on an object that is not a character, wheeled vehicle or tracked vehicle, or for an unknown name. The change lasts until Stop, which puts back the object's authored Played by setting. Works ongameObjectand on any object handle; in a multiplayer room only an authority script may call it.setBotBrain(name, settings)also replaces the bot's settings for the rest of the run, instead of its authored ones.settingsis a table with any ofspeed(how far the stick is pushed, 0.1 to 1, default 0.8),jumpsandfires(falseand it never presses that button), androamMin/roamMax(Roam's distance from home in metres, 1 to 100, default 4 and 14). A key left out, or one outside its range, is at its default. Without the table, the object keeps the settings it already has. Only Wander and Roam read them.getBotBrain()returns the brain's name, ornilwhile the player plays the object.
-- Scene script: a guard strolls a small patrol, and gives chase once the alarm goes off
local guard = scene.getObjectByName("Guard")
guard.setBotBrain("roam", { speed = 0.4, fires = false, roamMax = 6 })
-- Your own function, called from wherever your game raises the alarm
local function raiseAlarm()
guard.setBotBrain("roam", { speed = 1, roamMax = 30 })
end
The brains, the Played by setting and the scene script's onBotThink are covered in Characters.
Planet gravity (characters)
setCharacterUp(x, y, z)/setCharacterUp(nil)andgetCharacterUp(): the character's own up. Returns false on anything but a character.setCharacterGravity(x, y, z)/setCharacterGravity(nil)andgetCharacterGravity(): its own gravity, and the gravity it falls by.getCharacterHeading()/setCharacterHeading(yaw): its heading about its up, in radians.getCharacterLocalVelocity()/setCharacterLocalVelocity(x, y, z): velocity withyalong its up.getCharacterFrame():{up, forward, right}world vectors of its frame.
Single player only: setCharacterUp and setCharacterGravity raise an error in a multiplayer room. See Characters.
Rendering, GUI, and audio
getLightColor(), setLightColor(color), getLightIntensity(), setLightIntensity(value), getLightGroundColor(), setLightGroundColor(color), setText(text), setTextColor(r,g,b), setBackgroundColor(r,g,b,a), setFontSize(size), setFontWeight(weight), setItalic(italic), setTextAlign(align), setLetterSpacing(pixels), setTextOutline(r,g,b,width), setTextShadow(r,g,b,a,offsetX,offsetY,blur), setVisible(visible), setImageAsset(assetId), setSize(width,height), setWidth(width), setHeight(height), setOpacity(opacity), setColor(r,g,b), getColor(), clearColor(), setGuiPosition(x,y), setAnchor(anchor), setOrder(order), setAriaLabel(text), playSound(assetId, options), stopSound(soundId?, fadeOutSeconds?), isSoundPlaying(soundId), setSoundVolume(soundId, volume, rampSeconds?), setSoundPlaybackRate(soundId, rate, rampSeconds?), setSoundFilter(soundId, filter, rampSeconds?), and on a camera setFov(degrees), getFov(), setFollowDistance(distance), getFollowDistance(), setFollowSmoothing(seconds), getFollowSmoothing(), resetLook(), setCameraUpMode("target"|"world"), getCameraUpMode().
GUI width and height are pixels. setGuiPosition is normalized 0–1 inside the container; it is deliberately separate from the 3D setPosition(x,y,z). setAnchor accepts topLeft, top, topRight, left, center, right, bottomLeft, bottom, or bottomRight. setOrder affects children of row/column panels. See Editor basics for the full authoring layout model.
Colour components run from 0 to 1, not 0 to 255. The light calls take a table — setLightColor({r=1, g=0.5, b=0}) — while the GUI calls take separate numbers — setTextColor(1, 0.5, 0). The two are in different colour spaces. Light colours (setLightColor, setLightGroundColor) and the setColor tint are linear RGB, like material colours, so 0.5 renders much lighter than the CSS grey #808080; convert a CSS or hex channel c (0 to 1) above 0.04045 with ((c + 0.055) / 1.055)2.4, and one at or below it with c / 12.92. GUI colours (setTextColor, setBackgroundColor, and the setTextOutline and setTextShadow colours) and setParticleColor are sRGB as in CSS: a hex code's channels divided by 255. setText keeps the newlines and runs of spaces you write, so "Health: 3\nAmmo: 12" is two lines. On a GUI element setVisible works by setting opacity to 1 or 0, so setVisible(true) replaces a partial setOpacity; setOpacity clamps to 0–1. On a 3D object setVisible shows or hides the object and everything parented to it while the scene runs or in Preview, and its collider keeps working, so setVisible(false) makes an invisible wall; stopping a run in the editor restores it. setVisible(true) also shows an object authored hidden (Visible in Game off, visible: false) for the rest of the run, so a weapon or prop can wait hidden until a script reveals it; stopping a run in the editor hides it again. In a multiplayer room it is a presentation call and is not replicated: it changes only the screen whose script called it.
setOpacity(opacity) also fades a 3D object for the rest of the run: 1 is the authored look and 0 is invisible, and a transparent material keeps its own opacity scaled by the value. Like setScale it is visual only — the collider, triggers and raycasts are unchanged — and Stop restores the authored materials. It fades the object's own meshes; parented child objects keep theirs, so fade each part of a compound object. Call it every frame for a fade: a smoke puff can rise, grow with setScale and fade with setOpacity(1 - age / lifetime), then destroy() itself. To hide a 3D object outright, and everything parented to it, use setVisible(false).
setColor(r, g, b) tints a 3D object for the rest of the run. Each component is linear RGB from 0 to 1 and is clamped, and the tint multiplies the material's authored colour: a white material takes the colour exactly, (1, 1, 1) is the authored look, and a texture or a dark part such as a tyre is darkened rather than flattened to one colour. Like setOpacity it is visual only, so the collider is unchanged; it tints the object's own meshes, and parented child objects keep their colours. It combines with setOpacity in either order. getColor() returns the tint as {r, g, b}, or nil when none is set; clearColor() restores the authored colour and keeps any fade, and Stop restores the authored look. setColor and clearColor return false and do nothing on a GUI element (use setTextColor or setBackgroundColor), a light (use setLightColor) or a camera, and setColor also returns false for a component that is not a finite number. A car that flashes red when it is hit:
local flash = 0
function init()
gameObject.registerForCollisions()
end
function onCollisionEnter(other)
if other.approachSpeed > 3 then
gameObject.setColor(1, 0.2, 0.2)
flash = 0.3
end
end
function update(deltaTime)
if flash > 0 then
flash = flash - deltaTime
if flash <= 0 then
gameObject.clearColor()
end
end
end
GUI labels and buttons also take text-style calls. setFontWeight(weight) takes 100–900, or "normal" (400) or "bold" (700). setItalic(italic) takes a boolean, setTextAlign(align) takes "left", "center" or "right", and setLetterSpacing(pixels) takes −20 to 100. setTextOutline(r, g, b, width) draws an outline width pixels (0–20) outside each glyph. setTextShadow(r, g, b, a, offsetX, offsetY, blur) adds a drop shadow; a defaults to 1, the offsets to 2 pixels (±50) and blur to 0 (at most 50). Called with no arguments, setTextOutline() and setTextShadow() remove the effect, and a width of 0 or an alpha of 0 does the same. Values are clamped to these ranges, and other object types ignore the calls. An outline or a shadow keeps HUD text readable over a bright sky and dark asphalt alike:
gameObject.setFontWeight("bold")
gameObject.setTextOutline(0, 0, 0, 2)
gameObject.setTextShadow(0, 0, 0, 0.6, 2, 2, 4)
A guiProgressBar is a read-only bar for health, boost or a cooldown: getValue() returns its fill from 0 to 1 and setValue(value) sets it, clamped into 0–1, for the rest of the run. Like a slider it is a presentation element.
setAriaLabel(text) works on a guiButton, guiImage, guiPanel, guiSlider or guiProgressBar. It changes what a screen reader announces for the element for the rest of the run, for example a mute toggle that becomes "Unmute music". Passing nil or "" falls back to the button's text, then the object's name. It sets the same thing as the element's Accessible Label; see Editor basics.
Sliders
A guiSlider is a value the player drags while the game runs, for tuning a game live: a joint's strength, a volume, a difficulty. The player drags it with a mouse or a finger, or focuses it with Tab and uses the arrow keys (one step, or 1% of the range on a continuous slider), Page Up and Page Down (ten of those), and Home and End. While a slider has focus, those keys move only the slider, not the player or the camera.
The slider's own script hears each change:
function onValueChanged(value, final)
-- At most once per frame while dragging, with the latest value.
-- final is true on the call that ends the gesture: the pointer is
-- released, or a key is pressed. Do expensive work only then.
if final then gameStorage.set("strength", value) end
end
| Method | What it does |
|---|---|
getValue() | The slider's current value, clamped into its range and snapped to its step (on a guiProgressBar, its 0–1 fill). nil on any other object. Another script reads a slider with scene.getObjectByName("Strength Slider"):getValue(). |
setValue(value) | Moves the slider, clamped and snapped. Does not call onValueChanged. |
setRange(min, max, step) | A new range for the rest of the run. step 0 is continuous; leave it out to keep the current step. Clamps the value without calling onValueChanged. Returns false, changing nothing, unless min is less than max. |
A slider moves only while the game runs; a paused game's slider stays put. Like the rest of the GUI it is presentation only: in a multiplayer room each player has their own slider and the room's server never sees it.
playSound(assetId, options)
Plays a sound effect positioned at this object, which follows the object as it moves, and returns a sound id. Every call starts a new, independent instance, so calling it again while a looped sound is still playing layers a second copy rather than restarting the first. Keep the id if you will need to stop that instance. options is optional:
| Option | Meaning |
|---|---|
volume | 0–1, relative to the sound-effects volume. Default 1 |
loop | Repeat until stopped. Default false |
playbackRate | Speed multiplier; also shifts pitch. Default 1 |
fadeIn | Seconds to ramp up from silence |
refDistance, rolloffFactor, maxDistance | How the volume falls off with the listener's distance |
distanceModel | "linear", "inverse", or "exponential" |
filter | A filter table, as setSoundFilter takes, applied before the sound is positioned |
stopSound(soundId, fadeOutSeconds?) stops one instance; stopSound() with no id stops every sound playing on this object. isSoundPlaying(soundId) reports whether an instance is still playing. For music and non-positional sound, see Scene scripts, variables, and storage.
setSoundVolume(soundId, volume, rampSeconds?) and setSoundPlaybackRate(soundId, rate, rampSeconds?) change a playing sound, one this object or the scene started, by its id. volume runs from 0 to 1 and rate from 0.05 to 8, where 1 is as recorded and the pitch moves with the rate; both are clamped. The change ramps over rampSeconds (default 0, at most 60). Both return false for an id that is not playing; a sound still loading takes the change when it starts. Use them for continuous feedback rather than restarting a sound: start one looping engine sound in init(), then each frame set its rate from getVehicleRPM() with a ramp of about 0.05–0.1 seconds so it glides instead of stepping.
setSoundFilter(soundId, filter, rampSeconds?) puts a filter on a playing sound by its id, with the same rules as setSoundVolume. filter is {type="lowpass"|"highpass"|"bandpass", frequency=hertz, q=number}: type defaults to lowpass, frequency to 1000 (clamped to 10–22050) and q to 1 (clamped to 0.0001–30). nil takes the filter off. A lowpass or highpass sweeps in from fully open, and back out, over the ramp, and changing a filter that is already on ramps its frequency and q. The filter is applied before the sound is positioned, so a muffled engine still pans with the car. It returns false for an id that is not playing and for a table that is not a filter, such as an unknown type or a non-finite number. For a filter over the whole mix and for reverb, see Scene scripts, variables, and storage.
For impact sounds, scale volume by other.approachSpeed in onCollisionEnter, above a small threshold such as 0.5 m/s so resting jitter stays silent. For scraping or skidding loops, drive setSoundVolume from other.tangentialSpeed in onCollisionStay. See Collision callbacks for the fields and an example.
The camera calls change the lens and the built-in follow for the run; see Cameras and follow modes. setCameraUpMode("target" | "world") / getCameraUpMode(): whether a follow camera keeps the followed character's up (the default) or world up; runtime only. shake(intensity, duration), stopShake() and getShake() shake the drawn view; playCameraPath(stops, options), moveCameraTo(position, lookAt, duration, easing, options), stopCameraPath(blendOut?) and isCameraPathPlaying() fly the camera through a scripted move and ease it back to its follow mode. Both respect the player's Reduce camera motion setting; see Camera shake and scripted camera moves. Sound changes (filters included), camera changes (setCameraUpMode, shake and camera paths included), setScale, setOpacity, setColor/getColor/clearColor, the GUI text-style calls, setAriaLabel, the slider calls getValue, setValue and setRange, startTrail and the particle-emitter calls are presentation calls: in a multiplayer room the room server refuses them, so make them from a GUI, camera or "presentation" script.
Trails
startTrail(options) draws a flat ribbon behind a point on this object: skid marks, tyre tracks, light streaks, tracers, sword swipes. It returns a handle, or nil with a warning when the simulation is not running or the options cannot be used. Every option is optional:
| Option | Meaning |
|---|---|
offset | A point in the object's own space (default its origin), or {wheel = index} on a wheeled or tracked vehicle. A wheel offset follows that wheel's ground contact and pauses while the wheel is in the air |
width | Metres. Default 0.2, or the tyre's width for a wheel |
color | Linear {r=, g=, b=} from 0 to 1, or an sRGB "#rrggbb" string, which is converted to linear. Default white. Before 14 October 2026 a hex string was used as linear, so a trail coloured with one drew lighter than its hex code |
opacity | 0–1. Default 1 |
lifetime | Seconds each segment takes to fade. Default 2, at most 600 |
minDistance | Metres between samples. Default 0.1 (0.01–100) |
maxSegments | Default 128, from 2 to 1024 |
align | "camera" (the default) faces the viewer. "ground" lies flat on the surface below, leaving a gap where there is none; it is the default for a wheel. "up" lies flat in the object's own up plane. "axis" spans axis |
axis | For align = "axis": a direction in the object's own space, such as along a blade. Default {x=0, y=1, z=0} |
emissive, intensity | Additive and left out of tone mapping, so it can bloom; intensity brightens it (default 1, at most 20) |
emitting | false starts the trail paused |
Numbers out of range are clamped; a value of the wrong kind refuses the call. The handle has setEmitting(on), which pauses or resumes drawing while what is drawn stays and fades; isEmitting(); stop(), which stops it for good, lets it fade out and then removes it; clear(), which erases what is drawn; and isActive(), which is false once a stopped trail has faded. Dot and colon syntax both work. At most 64 trails exist at once. Trails fade on game time, so scene.setTimeScale slows them and 0 freezes them. Destroying the object stops its trails where they are and lets them fade, so a destroyed projectile leaves its streak; Stop removes every trail. A trail is only drawn: it never collides and is never replicated.
-- A glowing streak behind a projectile
gameObject.startTrail({ color = "#66ccff", width = 0.1, lifetime = 0.4, emissive = true, intensity = 3 })
-- A sword swipe along the blade, which points up the sword's local +Y
local swipe = gameObject.startTrail({ align = "axis", axis = { x = 0, y = 1, z = 0 }, width = 0.9, lifetime = 0.25, emitting = false })
-- swipe.setEmitting(true) as the swing starts, swipe.setEmitting(false) when it ends
-- Footprints laid flat on the ground under a character
gameObject.startTrail({ align = "ground", width = 0.3, color = { r = 0.25, g = 0.2, b = 0.15 }, opacity = 0.5, lifetime = 10 })
For skid marks on every wheel of a car, see Vehicles and navigation.
Particle emitters
On a particle emitter object (see Assets, materials, and shaders), emit(count) births count particles at once, whether or not it is emitting, up to its Max Particles, and returns how many were born. setEmitting(on) starts or stops continuous emission, isEmitting() reads it, setEmissionRate(rate) sets particles per second (0–1000), and setParticleColor(start, end) recolours its particles, live ones included, from start at birth to end (default start) at death; both are sRGB {r=, g=, b=} tables from 0 to 1, as in CSS. All of them last for the run only, and Stop restores the authored settings. On any other object emit returns 0 and isEmitting returns nil. The bundled lua/tyre_smoke.lua drives the rate from how fast the car it is parented to is sliding:
local car = nil
function init()
car = gameObject.getParent()
gameObject.setEmitting(false)
end
function update(deltaTime)
if not car then return end
local v = car.getLinearVelocity()
local right = car.getRight()
local sideways = math.abs(v.x * right.x + v.y * right.y + v.z * right.z)
local slip = math.min(1, math.max(0, (sideways - 2.5) / (8 - 2.5)))
if slip > 0 then
gameObject.setEmissionRate(60 * slip)
gameObject.setEmitting(true)
else
gameObject.setEmitting(false)
end
end
Vehicles, constraints, navigation, and animation
These are also on every object API. Their behaviour and parameters are documented on the pages linked below.
| Area | Members |
|---|---|
| Wheeled vehicles (Vehicles and navigation) | setDriverInput(forward,right,brake,handBrake), setForwardInput(forward), setRightInput(right), setBrakeInput(brake), setHandBrakeInput(handBrake), getVehicleForwardSpeed(), getVehicleRPM(), getVehicleGear(), isWheelInContact(index), getWheelContactNormal(index) |
| Tracked vehicles | setTrackDriverInput(forward,leftRatio,rightRatio,brake), setLeftRatio(ratio), setRightRatio(ratio), plus the shared forward, brake, speed, RPM, gear and wheel-contact calls above |
| Constraint motors: hinge, slider, path, swing-twist, six-DOF (Constraint motors) | setConstraintMotorState("off"|"velocity"|"position", part?), setConstraintTargetVelocity(value), setConstraintTargetPosition(value), getConstraintCurrentValue(), setConstraintMotorSettings({frequency, damping, maxForce, maxTorque}, part?), getConstraintMotorSettings(part?), setConstraintTargetOrientation(x,y,z,w), setConstraintTargetAngularVelocity(x,y,z), getConstraintRotation() |
| Navigation agents | registerForPathfinding(speed?), moveTo(x,y,z), followPath(waypoints), followWaypointPath(idOrName, traversal?), stopMovement(), isMoving(), getPathToTarget(x,y,z), getRandomNavPoint(radius) |
| Generated tracks | getTrackPath() — the centreline of a generated track mesh, or nil |
| Animation (Animation playback API) | playAnimation(name,loop?,blendTime?), stopAnimation(name?,fadeOutTime?), releaseAnimation(), setAnimationSpeed(speed,name?), getAnimationNames(), isAnimationPlaying(name?), enableAutoAnimation(config), disableAutoAnimation(), updateAutoAnimation(), getAnimationState(), preloadAnimations(names?), isAnimationReady(name), areAnimationsLoaded(), seekAnimation(name,time), getAnimationTime(name?), getAnimationDuration(name), getAnimationDiagnostics() |
| Animation timelines and markers (Animation playback API) | playAnimationTimeline(clip,options?), stopAnimationTimeline(), setAnimationTimelineSpeed(speed), seekAnimationTimeline(time), getAnimationTimeline(), getClipDuration(clip), getAnimationMarkers(clip?), and the callbacks onAnimationMarker(clip,name,time) and onAnimationTimelineFinished(clip). For characters, meshes and ragdolls; one timeline per scripted object |
| Animation layers (Animation playback API) | playAnimationLayer(layer,clip,options?), stopAnimationLayer(layer?,fadeOutTime?), setAnimationLayerWeight(layer,weight,fadeTime?), setAnimationLayerSpeed(layer,speed), seekAnimationLayer(layer,time), getAnimationLayer(layer), getAnimationLayers(), getAnimationMaskBones(mask), and the callback onAnimationLayerFinished(layer,clip). A clip on part of the skeleton (a mask such as "arms" or "upperBody") over the base animation, which keeps running underneath. For characters, meshes and ragdolls with a skeleton; presentation-only in a multiplayer room |
| Bones and sockets (Animation playback API) | getBoneNames(), getBoneWorldPosition(name), getBoneWorldRotation(name), attachToBone(object,boneName,offset?), detachFromBone(object?), getBoneAttachments(). For characters and meshes with a skeleton; presentation-only in a multiplayer room |
Timeline calls work in every multiplayer runtime. Only the authority may start or change another object's timeline; that object's own script receives the markers. An object with no script has no timeline: playAnimationTimeline on it warns and returns false, and the other timeline calls do nothing. getClipDuration and getAnimationMarkers work on any object.
Authored waypoint patrols
followWaypointPath(idOrName, traversal?) starts a route at its nearest stop, routing each leg over the navmesh. Traversal is "once", "loop" (default), or "pingPong"; a missing or incomplete route returns false. Choose speed with registerForPathfinding(speed). isMoving() remains true during waypoint waits, which use game time. followPath(points) retains its direct-polyline behavior.
The optional callback onWaypointReached(eventName, pathId, pointIndex) belongs to the moving object's own script. It runs only at stops with event names, on arrival before the wait; indices are 1-based. State is committed before callbacks run, so the handler may safely issue another movement command. Explicit moveTo, followPath, followWaypointPath, or stopMovement cancels an automatic inspector patrol for the rest of that run. Resume explicitly with followWaypointPath or start a fresh Play. In rooms, starting or changing navigation is authority-only.
scene.getWaypointPath(idOrName) returns world-space point metadata or nil, including for object scripts. For editor authoring, eligible bodies, route validation and examples, see Authored waypoint patrols.
Ragdolls
Ragdoll objects only. Every bone call takes a name from getRagdollBones(). An unknown bone returns nil or false and warns once.
| Call | What it does |
|---|---|
getRagdollBones() | The bones with a physics body, parents first. Empty until the ragdoll is built. |
getRagdollMode() / setRagdollMode(mode) | "animated", "powered" or "limp", for the rest of the run. |
addRagdollBoneImpulse(bone, x, y, z, point) | An impulse (N·s) on one bone, at an optional world point. |
addRagdollBoneForce(bone, x, y, z, point) | A force (N) on one bone for the next physics step. |
setRagdollBoneVelocity(bone, x, y, z) | One bone's velocity. |
getRagdollBonePosition(bone), getRagdollBoneRotation(bone), getRagdollBoneVelocity(bone) | Read from the bone's physics body. |
setRagdollMotorStrength(strength, bone) | Powered motor strength: a multiplier (1 default, 0 slack, up to 10) or {frequency=, damping=, maxTorque=}. All joints, or one bone's joint to its parent. |
The impulse, force and velocity setters return false while the ragdoll is animated. grab({bone = "..."}) holds a single bone. Stop restores everything.