RunService
Per-step events (heartbeat, stepped, renderStepped) and where the code is running.
- Get it:
import { RunService } from '@rally/sdk'
Each step of the game runs, in order: due task work, stepped, physics, then heartbeat. The
game server steps 30 times a second (a step covers at most 0.25 seconds, however long the
server was busy); players’ devices step once per frame. Each handler gets dt, the seconds since
the previous step.
Changes the server makes in heartbeat replicate about 20 times a second. For purely visual
motion, animate on players’ devices instead.
Methods
Section titled “Methods”isServer
Section titled “isServer”isServer(): booleanTrue on the game server, and in Rally Studio’s Play.
isClient
Section titled “isClient”isClient(): booleanTrue on a player’s device, and in Rally Studio’s Play.
Events
Section titled “Events”heartbeat
Section titled “heartbeat”Arguments: dt: number
Every step, after physics (dt in seconds).
stepped
Section titled “stepped”Arguments: dt: number
Every step, before physics.
renderStepped
Section titled “renderStepped”Arguments: dt: number
Client: every frame, before rendering.
Examples
Section titled “Examples”A spinning part
Section titled “A spinning part”import { Part, RunService, Vector3, getChild, workspace } from '@rally/sdk';
const spinner = getChild(workspace, 'Spinner', Part);RunService.heartbeat.connect((dt) => { spinner.rotation = spinner.rotation.add(new Vector3(0, 90 * dt, 0)); // 90 degrees a second});