natiny.physics.set_rotation_locks

Lua
natiny.physics.set_rotation_locks(body, lock_x, lock_y, lock_z)

Locks or unlocks rotation of a body around each world axis independently. The solver cannot turn the body around a locked axis, while the axes left free keep responding to gravity, contacts and impulses.

Parameters

Name Type Description
body number Body handle
lock_x boolean true to prevent rotation around the world X axis (pitch)
lock_y boolean true to prevent rotation around the world Y axis (yaw)
lock_z boolean true to prevent rotation around the world Z axis (roll)

Example

Lua
-- Stays upright, but is still free to spin around Y
natiny.physics.set_rotation_locks(player, true, false, true)

Notes

  • Rotation is free on every axis when a body is created.
  • All three arguments are applied on every call: an axis passed false is released, not left alone.
  • Locking an axis clears the angular velocity around it, so a body that was already turning stops rather than keeping the rotation it had.
  • The body can still be turned around a locked axis by hand through natiny.entity.set_rotation.
  • natiny.physics.set_fixed_rotation is the same call with one value for all three axes; either call overwrites what the other set.
  • Linear motion is unaffected.
  • Passing a handle that is not a live body has no effect.