This Tutorial builds up on the graph created in Tutorial 1 - Setting Up a Simple Graph.
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
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.
After changing the type, you can set a minimum and maximum range for the character's speed.
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.
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.
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
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.
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.
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.
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"
The Animation name from the Walk state has been copied over to the new state as well.
As a last step, the Speed Selection Criteria for the Run needs to be adjusted.
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
Because a new Input was added that needs to be bound to the code, the graph cannot be hot reloaded.