Language:
Page Info
Skill Level:
Engine Version:

3. Finishing Character Setup

Choose your OS:

In this section, we will finish setting up the Character by implementing the scripts that control our Character based on Player Input.

  1. Open the MyCharacter Blueprint.

  2. In the graph, Right-click and add the InputAxis MoveForward and InputAxis MoveRight Events.

  3. Hold Control and drag in the DisableMovement variable and connect it to the Condition on a Branch on each Event.

  4. Set the rest of node network up as shown below.

    Click image for full view.

    Here we are allowing character movement only if DisableMovement is False. We are doing this to prevent character movement where no animation exists, for example, we have a Prone Idle animation however we do not have a Prone Crawl animation. To prevent players from sliding around the ground when prone, we will disable movement.

  5. Right-Click and add the InputAxis Turn and InputAxis LookUp Events.

  6. Connect the Turn Event to an Add Controller Yaw Input node and the LookUp Event to a Add Controller Pitch Input node.

    Character_MouseInput.png

  7. Right-click in the graph and add the InputAction Jog Event.

  8. In the MyBlueprint window, click the Show inherited variables checkbox and Control + drag the CharacterMovement into the graph.

    Character_JogA.png

  9. Hold Alt and drag in the Jog Pressed variable, then hold Control and drag in the Crouch Pressed variable.

  10. Set up the node network making sure to check "Jog Pressed" in the appropriate Set node as shown below:

    Click image for full view.

    Here we are setting Jog Pressed to True when Jog is Pressed, then off the Character Movement Component, we are setting the characters Max Walk Speed to 375 (you can adjust this value to increase/decrease Jog speed).

    When Jog is Released, we are checking if we are crouched, and if so we are setting Walk Speed to 160 (our crouch walk speed). If we are not crouched, we are setting Walk Speed to 200 (our default walking speed). This allows us to enter a Jog from either a crouch or walking state and return to it appropriately.

  11. Right-click in the graph and add the InputAction Crouch Event.

  12. Hold Alt and drag in the Crouch Pressed variable, then hold Control and drag in the Jog Pressed and Prone Pressed variables.

  13. Set up the node network making sure to check "Crouch Pressed" in the appropriate Set node as shown below:

    Click image for full view.

    For the Crouch script, we are first checking if we are currently Prone in which case we will not allow you to crouch (only reason we are doing this is we do not have an animation to go from Prone to Crouch and vice-versa, if you had the animations, you would probably want to allow the player to enter a Prone state from Crouch).

    We used a FlipFlop node as a toggle for our crouch rather than requiring a sustained crouch button press (this is optional depending on the method you prefer). When first pressed, we set Crouch Pressed to True and set the Max Walk Speed to 160. When pressed a second time to toggle crouch off, we check if we are entering a Jog from crouch (if so we set walk speed to 375) if not, we set walk speed back to 200.

  14. Right-click in the graph and add the InputAction Prone Event.

  15. Hold Alt and drag in the Prone Pressed and DisableMovement variables.

  16. Hold Control and drag in the Crouch Pressed variable.

  17. Set up the node network making sure to check "Prone Pressed" in the appropriate Set node as shown below:

    Click image for full view.

    For the Prone script, we are first checking if we are currently Crouched and if so, not allowing you to enter Prone state (as mentioned, since we do not have the transition animations). We then used a FlipFlop node again to toggle between Prone states.

    When pressed the first time, we are setting Prone Pressed and DisableMovement both to True to allow us to enter the prone state and disable our character's movement. When pressed a second time, we are setting Prone Pressed to false to exit the prone state, we then add a bit of a delay (set to 1.4) before re-enabling movement (to prevent the player from moving around while the animation plays of returning to a standing state).

  18. Right-click in the graph and add the InputAction Jump Event and drag in the CharacterMovement from the MyBlueprint window.

  19. Hold Alt and drag in the Jump Pressed variable, then Control drag in the DisableMovement and CrouchPressed variables.

  20. Set up the node network making sure to check "Jump Pressed" in the appropriate Set nodes as shown below:

    Click image for full view.

    For the Jump script, we are first checking if we are either Prone or Crouched. If neither are true, we are then using the CharacterMovement component to determine our current velocity and if it is greater than 0, which would mean that we are moving.

    We then set how high the character can jump based on whether or not they are moving by setting the JumpZVelocity to 365 (for a moving character) or 340 while we are stationary. In either case, we set Jump Pressed to True and set Jump Pressed to False when Jump is released.