Tutorial 2 - Basic Locomotion

Tutorial 2 - Basic Locomotion

This Tutorial builds up on the graph created in Tutorial 1 - Setting Up a Simple Graph.

Idle, Walk and Run

Step 1: Adding a new State

  • Open the graph created in Tutorial 1.
  • Add a View to the graph and call it "Locomotion". You can add a new view through the Graph -> Add View menu.
  • You can change the name of the newly created view by selecting it and editing the properties on the right.

  • Place the Idle State in the view by selecting it in the States Tab and dragging it into the middle of the view.

Tip

Adding a new view is not necessary for the basic functionality of this tutorial, as they are only needed to set up transition animations, but arranging states in a view rather than just having the in the list in the States Tab gives a better overview and the states are automatically grouped by function, which makes it easier to find them again later

  • Add a new state to the graph through the Graph -> Add State Menu. This will add a new state to the state list. The name will be a default name, like state0 or similar.
  • Select the state and change the name in the Node Details Panel on the bottom. Rename the state to "Walk".

  • Drag and drop the state into the view with the Idle state.

Step 2: Setting up the Walk State Parameters

  • Select a Walk Animation for the Character and assign it to the newly created "Walk" state (as done in Tutorial 1).
  • When the state is selected, the character in the preview window should now play the Walk Animation (you might need to deselect the state once first).
  • Select the "Movement Cycle" Preset from the Drop-Down list. This will make the asset both looping and use Time Warping for transitions.

Step 3: Creating a new Input for the Movement Speed

To allow the graph to decide when to select the Idle and when the Walk State, it must know about the character's movement speed. This information is sent to the Graph by default from the code, but the graph needs to listen to it in order to use it.

  • Select the Inputs Tab on the left where the Modifier and State Tab are located as well to see a list of existing Inputs in the graph.

  • Create a new Input through the menu Graph -> Add Input. A new input with a default name will be added at the bottom of the list.

  • Select the new Input. On the right panel below the Preview window the Inputs properties will show up. The Code sends the speed information to a variable named "ActualMoveSpeed", so this is the name the new input has to be set to.
  • Since the speed is a floating point number, select the type "Float" from the DropDown list for this Input.

After changing the type, you can set a minimum and maximum range for the character's speed.

  • Set the Range from -50 to +50 and set the Priority to a value of 20.
    Your new Input's Properties should look like in the picture below.

Tip

In the event that the AnimationGraph cannot find a state that matches all current inputs it will start ignoring Inputs with low priorities in order to find a state it can enter and play. Always set things like Actions and Signals to high priorities, while Inputs like Item or Stance should have lower values.

Step 4: Setting up the Selection Criteria

To make the graph choose between the Idle and the Walk based on the speed, the new Inputs needs to be set up in their Selection Criteria.

  • Select the Walk state in the view or in the States Tab.
  • In the Properties panel on the right is located a "Selection Criteria" Panel.
  • By clicking on the + sign in front of the "Unused" Tab the panel will display a list of all Inputs that the graph is listening to, but that are not currently active on this state.
  • Choose "ActualMoveSpeed" from the list and select "Value Range" from the DropDown list.

This will remove the Input from the tab of unused ones and bring it up to the top, to the Active Selection Criteria. There are two new edit lines to enter the range of speed in which this Input will be valid. Set it to the values:

Min: 0.05
Max: 2.0

Tip

The speeds in the SDK are setup to work nicely with a gamepad. If you want to use only a keyboard and still see the Walk, set a maximum speed value of 3.0 for the selection criteria of the Walk State. The Walk and Run Speeds that the code uses to move the character (depending on his Stance) are set up in his lua file. See Game/Scripts/Entities/actor/player.lua to see the hero character's speeds.

The Idle State also needs the "ActualMoveSpeed" set up in it's selection criteria. Repeat the steps performed on the Walk state and set the range values to:

Min: 0.0
Max: 0.1

You don't need to change anything in the "ExampleInput" that is already set up on this state. The Selection Criteria on the Idle state should look like the picture below.

Tip

Always use ranges on floats, do not test against specific value, as the precision will not be high enough. Creating overlap on the ranges like done here with the Idle and Walk state will prevent nasty state jumping when the speed is exactly on the border between two states.

Step 5: Adding a Run State by cloning the Walk

Since the Run is very similar to the Walk state, it saves time to clone the Walk instead of creating a completely new state and setting all parameters again.

  • Select the Walk state.
  • On the right in the Properties panel select the entry "Clone".

This will create an exact copy of the Walk state and put it into the States Tab List. The name of the state will be automatically extended with an "_1"

  • Select the new state, rename it to "Run" and drag & drop it into the view with the Idle and the Walk state.

The Animation name from the Walk state has been copied over to the new state as well.

  • Select a Run Animation from the Character Editor and assign it to the Run State.

As a last step, the Speed Selection Criteria for the Run needs to be adjusted.

  • Select the Run State, go to the Properties panel and change the ranged values for "ActualMoveSpeed".
    Min: 1.5 // (use 2.5 here if you don't have a gamepad and set 3.0 as a max value for Walk)
    Max: 8.0

Step 6: Seeing it ingame

Because a new Input was added that needs to be bound to the code, the graph cannot be hot reloaded.

  • Save the graph and restart the Editor for the changes to take effect.
    After jumping ingame, the Character should now stand, walk and run correctly (for Keyboard control you might need to press Shift or hold Ctrl for the speed changes to take effect if you didn't adjust the speed values in the lua file).