Lumberyard
User Guide (Version 1.16)

Working with the Input Component

You can create an .inputbindings file for an Input component and specify the input values and events.

Creating an Input to Event Binding Asset

Follow these steps to create an .inputbindings file.

To create an input to event binding asset

  1. Create an entity.

  2. In the Perspective viewport, select the entity.

  3. In the Entity Inspector, click Add Component and then add the Input component.

  4. In the Entity Inspector, under Input, click the Input Bindings Editor icon to open the Asset Editor.

    
                            Open the Asset Editor in the
                                    Input component properties window.
  5. In the Asset Editor, choose File, New, Input Bindings.

  6. Enter a name for the .inputbindings file and then click Save.

Creating Input Event Groups

After you create your .inputbindings file, you can add input event groups for different actions.

To add an input event group

  1. In the Asset Editor, for your .inputbindings file, click the + icon.

    
                            Add an Event Group for the
                                    .inputbindings file in the
                                    Asset Editor.
  2. For Event Name, enter a name for your event, such as Action.

    
                            Specify a name for the Event Name for the
                                    .inputbindings file in the
                                    Asset Editor.

Creating Event Generators

After you create your input event group, you can add event generators to the group. An event generator is a handler that generates the named event. For example, a pressed key, a held mouse button, or a series of actions on a game controller will result in the named event.

To add an event generator to your input event group

  1. In the Asset Editor, for your input event group, next to Event Generators, click the + icon.

  2. In the Class to create window, select Input and then click OK.

  3. Specify your changes for the event generator. Each event generator has a set of properties that you can customize.

    Event Generator Properties

    Name Description
    Input Device Type

    Type of device that generates the input. Select from a list of available devices such as keyboard, mouse, and gamepad.

    Input Name

    List of input options that depend on the selected input device type. For example, if you select keyboard for the Input Device Type, a list of possible keystrokes appear in this list, such as keyboard_key_edit_space.

    Event value multiplier

    Multiplier by which to scale the input value.

    Default value: 1.0

    Valid values: -∞ to ∞

    Dead zone

    Specifies the threshold in which an event is generated.

    Values below this number are inactive and events are not generated.

    Values above this number are active and events are generated.

    For example, you can specify gamepad for the Input Device Type and gamepad_thumbstick_r for the Input Name. If you specify a Dead zone value of 0.50, the thumbstick must move more than 50% to the right before the event is generated.

    Default value: 0.2

    Valid values: 0.001 to ∞

    Example

    The following .inputbindings file specifies a keyboard for the device type and the spacebar for the input name.

    
                                Input bindings configuration example in the
                                        Asset Editor.
  4. Save your .inputbindings file.

  5. In the Entity Inspector, in the Input component, for Input to event binding, click the browse () icon and select your .inputbindings file.

Mapping Input Events to Gameplay Actions

After you create an .inputbindings file and specify your input events, you can use a Script Canvas graph or Lua script to map the input events to gameplay actions. You can create your graph in a visual scripting environment with the Script Canvas editor or write your own scripts with the Lua Editor (Lua IDE).

Using a Script Canvas Graph for Input

You can create a Script Canvas graph that maps to your input events. For more information, see Creating Gameplay with Script Canvas.

To use a Script Canvas graph for input

  1. In the Perspective viewport, select the entity.

  2. In the Entity Inspector, click Add Component and then add the Script Canvas component.

  3. In the Script Canvas component, for Script Canvas Asset, specify a Script Canvas graph like the following.

    Example Script Canvas Graph

    In the following graph, the Input Handler node maps the Event Name Action to the .inputbindings file.

    
                                    Example Script Canvas graph for the
                                            Input component.

Using a Lua Script for Input

You can also create a Lua script that maps to your input events. For more information about Lua, see Writing Lua Scripts.

To add a Lua script for input

  1. In the Perspective viewport, select the entity.

  2. In the Entity Inspector, click Add Component and then add the Lua Script component.

  3. In the Lua Script component, specify a Lua script file like the following.

    Example Lua Script

    The following Lua script maps the Event Name Action to the .inputbindings file.

    local tutorial_input = { Properties = { }, } function tutorial_input:OnActivate() self.Inputs = {} self.Inputs.OnPressed = function(_, value) TransformBus.Event.SetLocalScaleZ(self.entityId, 2.0) end self.Inputs.OnHeld = function (_, value) TransformBus.Event.RotateAroundLocalZ(self.entityId, 0.01) end self.Inputs.OnReleased = function (_, value) TransformBus.Event.SetLocalScaleZ(self.entityId, 1.0) end self.InputNotificationBus = InputEventNotificationBus.Connect( self. Inputs, InputEventNotificationId("Action") ) InputEventNotificationBus.Connect( self.Inputs, InputEventNotificationId("Action") ) end function tutorial_input:OnDeactivate() self.InputNotificationBus:Disconnect() end return tutorial_input

Testing Your Input Events

After you specify the Script Canvas graph or Lua script, you can test your input events.

To test your input events

  1. In the Perspective viewport, select your entity.

  2. In the Entity Inspector, click Add Component and then add the Mesh component.

  3. For Mesh asset, specify a mesh asset file. This gives your entity a shape. For example, you can specify the lumberyard_version\dev\SamplesProject\Objects\Primitives\cube_001.cgf file.

  4. Press Ctrl+G to enter game mode.

  5. Press the keyboard spacebar so that your entity rotates on the local z-axis.

    Example

    
                                Input bindings configuration example in the
                                        Asset Editor.
  6. Press Esc to exit game mode.