Skip to content

Input entities

Context-sensitive input uses three components:

  • InputContext groups actions with Enabled, Priority, Sink, and SelectionScope.
  • InputAction is a child of a context with Kind ("Button", "Axis1", or "Axis2"), Enabled, Replicated, Drives, and Deadzone.
  • InputBinding is on the action entity (one binding has up to 16 inputs across Inputs, Negative, Up, Down, Left, Right, and Stick, plus optional UIButton and Keybind).

Every InputBinding field and InputContext.Enabled, InputAction.Enabled, and InputAction.Deadzone can be overridden per client with Override for local rebinding. See Replicated input actions for streaming action state to the server.

-- Client script: aim with MouseRight and steer with WASD or LeftStick.
local gameplay = World.Spawn({ InputContext = { Priority = 1000 } })

local aim = World.Spawn({
    InputAction = { Kind = "Button" },
    InputBinding = { Inputs = { "MouseRight", "LeftTrigger" } },
})
aim.Parent = gameplay

local steer = World.Spawn({
    InputAction = { Kind = "Axis2" },
    InputBinding = {
        Up = { "W", "ArrowUp" },
        Down = { "S", "ArrowDown" },
        Left = { "A", "ArrowLeft" },
        Right = { "D", "ArrowRight" },
        Stick = "LeftStick",
    },
})
steer.Parent = gameplay

function Update(dt: number)
    local aimAction = aim.InputAction
    local steerAction = steer.InputAction
    if aimAction and aimAction:IsDown() then
        print("aiming")
    end
    if steerAction then
        local v = steerAction:GetVector()
        if v.Magnitude > 0 then
            print(v.X, v.Y)
        end
    end
end