Skip to main content
Hook that sets up IK control for a MuJoCo site. Pass null to disable IK (safe to call unconditionally per React hook rules).

Usage

With Custom Solver

useIkController is intentionally open-ended. You can pass ikSolveFn for your own IK implementation, wrap the returned IkContextValue in your own hook, or build a plugin-style React component that reads/writes the IK target, simulation data, or actuator controls directly. Built-in helpers such as IkGizmo and useKeyboardIkTarget are optional consumers of the same controller state, not required control paths.

Config

Pass an IkConfig object or null: By default, useIkController infers scalar hinge/slide joints by walking from the site body toward the model root. For nonstandard actuator layouts, pass explicit ordered names or a selector:

Return Value

Returns IkContextValue | null. Returns null when config is null.

Methods

Refs

Example: Keyboard/Gizmo Coexistence

A common pattern is disabling IK when keyboard control takes over. Pass the ik value to your controller:
The gizmo re-enables IK automatically when dragged.

Example: Waypoint Following

Built-in Solver Details

The default solver uses Damped Least-Squares (DLS) with finite-difference Jacobian:
  • Position weight: 1.0
  • Rotation weight: 0.3
  • Tolerance: 1e-3
  • Finite-difference epsilon: 1e-6
  • Method: Finite-difference Jacobian + pseudoinverse
The solver tracks the best solution across iterations and returns it even if tolerance isn’t reached.

Reset Behavior

When the simulation is reset (via api.reset(), api.applyKeyframe(), or api.loadScene()), useIkController automatically:
  • Syncs the gizmo to the current site position
  • Stops any in-progress gizmo animation
  • Disables IK solving
When IK is enabled, it overwrites data.ctrl for the arm joints inside useBeforePhysicsStep. Disable IK when running your own control (policies, teleoperation, etc.).