Skip to main content
IK is provided by the useIkController() hook — it is not part of the core MujocoSimAPI. The hook returns an IkContextValue that you pass to <IkGizmo> or use directly.

Setup

IkContextValue Methods

setIkEnabled(enabled)

Enable or disable the IK solver.
When IK is enabled, it overwrites data.ctrl for the arm joints inside useBeforePhysicsStep. Disable IK when running your own control (policies, teleoperation, etc.).

moveTarget(pos, duration?)

Animate the IK target (gizmo) to a new position.

syncTargetToSite()

Snap the IK gizmo to the current site position.
Useful after programmatic joint changes to re-align the gizmo with the actual end-effector.

solveIK()

Run IK solving manually (without the gizmo).
Returns: number[] | null — joint positions, or null if solver failed.

getGizmoStats()

Get the current IK gizmo position and orientation.
Returns: { pos: THREE.Vector3, rot: THREE.Euler } | null

Disabling IK

Pass null to useIkController() to disable IK entirely. This is safe to call unconditionally (React hook rules):

Joint and Actuator Selection

The default config is model-aware:
The controller finds the site body and infers scalar hinge/slide joints by walking toward the model root. For nonstandard MJCFs, multi-arm scenes, or actuator orders that do not match qpos order, pass explicit selectors:

Custom IK Solver

Pass ikSolveFn to the config to replace the built-in solver:
When to use a custom solver:
  • Analytical IK — faster and more reliable for specific robot geometries
  • Learned IK — neural network solvers trained on your robot
  • External solvers — calling into WASM-compiled libraries (e.g. KDL, TRAC-IK)
  • Constrained IK — solvers that enforce joint limits, collision avoidance, or task-space constraints

Built-in Solver Details

The default solver uses Damped Least-Squares (DLS) with finite-difference Jacobian:
  • Max iterations: 50 per frame (configurable)
  • Damping: 0.01 (configurable)
  • Position weight: 1.0
  • Rotation weight: 0.3
  • Tolerance: 1e-3
  • Method: Finite-difference Jacobian + pseudoinverse