Skip to main content
Register a callback that runs before mj_step every physics frame. This is the primary hook for writing control logic.

Signature

Usage

Setting Actuator Controls

Applying Forces

PD Controller

Execution Order

Composability

Multiple useBeforePhysicsStep hooks compose correctly. Each callback adds to the simulation state rather than overwriting:
Both run each frame. Since the provider zeros qfrc_applied at the start, you should add to it (not assign).

Notes

  • The callback receives the same model/data objects that mj_step will use
  • If using IK (via IkGizmo), your before-step runs first, then IK may overwrite ctrl. Disable IK with api.setIkEnabled(false) when writing your own control.
  • The callback is called at physics rate, not render rate. Multiple physics steps may run per render frame.