Skip to main content

Set an analog-stick position (:set_stick)

This method is available in versions after 20260805

Declaration​

success, err = pad:set_stick(stick, x, y)

Parameters​

  • stick
    String. "left" or "right"; matching is case-insensitive
  • x
    Number. A finite value in [-1, 1]; positive moves right and negative moves left
  • y
    Number. A finite value in [-1, 1]; positive moves up and negative moves down

Returns​

  • success
    Boolean. True if the analog-stick position is set; false if the device is disconnected or busy, or if input delivery fails
  • err
    String. Error message when the operation fails

Description​

  • 0, 0 centers the analog stick
  • The analog stick moves directly to (x, y) without generating a smooth movement sequence
  • Invalid argument types, unknown stick names, non-finite numbers, and out-of-range values raise Lua argument errors

Example​

local pad = assert(gamepad.connect())

assert(pad:set_stick("left", 0.5, 1))
assert(pad:set_stick("left", 0, 0))
assert(pad:disconnect())