Skip to main content
Methods for controlling the simulation lifecycle and timing. Access via ref on MujocoCanvas or useMujoco().api inside R3F.

reset()

Reset the simulation to its initial state.
api.reset();
Applies homeJoints from the scene config (if set), runs mj_forward, and calls the onReset callback.

setPaused(paused)

Pause or resume the simulation.
api.setPaused(true);   // Pause
api.setPaused(false);  // Resume
paused
boolean
required
Whether the simulation should be paused.

togglePause()

Toggle pause state. Returns the new paused state.
const isPaused = api.togglePause(); // true or false
Returns: boolean — the new paused state.

step(n?)

Advance the simulation by n steps while paused.
api.step();    // Advance 1 step
api.step(10);  // Advance 10 steps
n
number
default:"1"
Number of physics steps to advance.
Has no effect if the simulation is not paused.

setSpeed(multiplier)

Set the simulation speed multiplier.
api.setSpeed(2.0);  // 2× speed
api.setSpeed(0.5);  // Half speed
api.setSpeed(0.1);  // Slow motion
multiplier
number
required
Speed multiplier. 1.0 = real-time, 0.5 = half speed, 2.0 = double speed.

getTime()

Get the current simulation time in seconds.
const t = api.getTime(); // e.g., 1.234
Returns: number — simulation time in seconds.

getTimestep()

Get the current simulation timestep.
const dt = api.getTimestep(); // e.g., 0.002
Returns: number — timestep in seconds.