3. Setting up the Character Blueprint

So far we have set up our Blend Space and modified our Animation Blueprint to use that Blend Space, our last step involves providing a way for the player to adjust the parameters that drive our Blend Space inside our Animation Blueprint. The Direction we will not need to worry about since it is determined based on the orientation of our character, however Speed we need to provide a way to drive this value.

Steps

  1. In the Content Browser under Content/AnimStarterPack open the Ue4ASP_Character Blueprint.

  2. In the graph, find the Crouching section and Right-click and add a C Keyboard Event.

    Character1.png

    This AnimBlueprint was built with the expectation that there is an Action Mapping called Crouch (which is why a warning appears). Since a Crouch Mapping does not exist in a fresh project, to get rid of the warning we will replace it with the C Key Event so that the player crouches when C is pressed.

    If you do not see a warning, you can use the exisiting Crouch Mapping instead of the C Key with the setup below.

  3. Drag off the Pressed pin and add a FlipFlop node, then connect the A and B pins as shown below.

    Character2.png

    This will allow the player to C to enter/exit the crouched state instead of holding C to crouch.

  4. Inside MyBlueprint, click the Show Inherited Variables box, then hold Ctrl and drag the CharacterMovement into the graph.

    Character3.png

  5. Drag off the CharacterMovement node in the graph, search for and add the Set Max Walk Speed node and set it to 125.

  6. Duplicate the Set Max Walk Speed node and set the new node to 150, then connect the nodes as shown below.

    Character4.png

    Here we are setting the cap at which the character can move. The movement of the character is what determines the Speed variable in our Animation Blueprint and Blend Space and causes the character to blend between the different animations for walking or jogging.

  7. Below the Crouch section, Right-click in the graph and add the Left Shift Key Event.

  8. Drag off the Pressed pin and add a Branch node, then also add a Branch of the Released pin.

  9. For the Condition for both, Right-click search for and add Get Crouch Button Down and connect as shown.

    Character6.png

  10. Select, then duplicate the CharacterMovement and Set Max Walk Speed nodes from the Crouch section.

  11. Connect off the False pins of each Branch as shown below and set the Max Walk Speed values to 270 and 150.

    Character7.png

    In this example we are only allowing the player to sprint if they are not currently crouched.

  12. In the My Blueprint panel select Character Movement.

  13. In the Details panel for Character Movement, set Max Walk Speed to 150 and Max Walk Speed Crouched to 125.

    Character8.png

    Here we are setting the default values for our character movement walk speed.

  14. In the Components panel click the Mesh.

  15. In the Details make sure that the AnimClass is set to use UE4ASP_HeroTPP_AnimBlueprint.

    Character10.png

    If it is already set, do not worry. If it is not, be sure to set it so that the character uses the Animation Blueprint we've modified.

  16. Click Compile and Save then close the Blueprint.

  17. In the Level Editor Viewport, delete the default character that is placed in the level.

    Character9.png

    Deleting this character will make sure that you spawn in using the Animation Starter Pack character when playing the game.

  18. Click Play to play in the editor.

End Result

When playing in the Editor, using WASD to move around, the character will now walk by default and blend between walking animations when changing directions. If you press C to crouch, the character will now stay in a crouched position while walking at a slightly reduced speed than found when standing/walking. While standing, pressing and holding Left Shift while using WASD will cause the character to blend from the walk/aim animation to a lowered/aim jog animation, essentially creating a "sprint" for the character.