Input entities¶
Context-sensitive input uses three components:
InputContextgroups actions withEnabled,Priority,Sink, andSelectionScope.InputActionis a child of a context withKind("Button","Axis1", or"Axis2"),Enabled,Replicated,Drives, andDeadzone.InputBindingis on the action entity (one binding has up to 16 inputs acrossInputs,Negative,Up,Down,Left,Right, andStick, plus optionalUIButtonandKeybind).
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