run-test-sprint-project

Because the Player Character that the system created for that Movement speed is set in the Character Movement : Walking property of Max Walk Speed, which defaults to 600, which is equivalent to walking speed. Therefore, this project will improve the player character's movement system to be able to run (Sprint). We will assign a button to receive input. When the player presses this button while the Player Character is moving, the value of the Max Walk Speed variable will be set to 2200, and when the player stops pressing the button, the speed will return to the default value.



Create a project

Initially, create a project by selecting Template as type First Person and setting it as Blueprint.


Set the input button to increase the speed.

Open the Edit menu from the top menu of the program window and select Project Setting. A window will appear.

menu-project-setting

On the left-hand side of the window is a list of settings. Go to the Engine category and select Input. Details will appear on the right-hand side.

input-details

In the Blinding category, click the (+) sign after Action Mapping to create a new Action Mapping.

input-binding

Name it Sprint , and then set the key for this action to Left Shift .

action-mapping

Explore the Player Character Control Script

In the main program window, go to the Content Browser tab, go into the Content > FirstPersonBP > Blueprints folder, and open the Blueprint named FirstPersonCharacter.

open-first-person-character

Click on the Event Graph tab, you will find Script commands, which are the default programs of the program, organized into groups.

first-person-event-graph

Trigger Node (red node) is a node that receives input signals as defined in Action Mapping or Axis Mapping.


Improved Script to add Sprint ability to Player Character.

On the Component tab, click on CharacterMovement (Inherited). In the Details tab, on the right side, the Player Character's default properties will be displayed. In the Category Movement: Walking category, the Max Walk Speed value is set to 600. To increase the movement speed for the Player Character, we will create a set of commands to change the value of Max Walk Speed as we want.

character-movement-details

Click on CharacterMovement (Inherited) and drag it over the graph to create a Character Movement node. This node acts as a Target for changing the Player Character's Max Walk Speed.

node-character-movement

Add an InputAction Sprint node by right-clicking on an empty area and searching for Sprint. This node listens for input signals from the Left Shift key.

add-sprint-node
sprint-node

Add 2 Set Max Walk Speed nodes and set values to 2200 and 600 respectively. This node sets values for Max Walk Speed variables.

add-set-max-walk-node
show-max-walk-node

Then connect the nodes together as shown

connect-node-all

The execution of this command starts when the player presses the Left Shift key, which is the key for creating Input that sends a signal to the InputAction Sprint node. If the state is Pressed, the Max Walk Speed variable is set to 2200. by the Set Max Walk Speed node, but if the status is Released, then the Max Walk Speed variable is set to 600.


Add a Print String node to display the values on screen.

To run a test project To be able to notice the change in Max Walk Speed, we will have it displayed on the screen when the Left Shift key is pressed or released. We add two Print String nodes and connect them as shown.

complete-connect-all-node

Run test project

While pressing the button to move the player and then press the left shift button, you will see that the player will move faster and in the upper left corner of the screen will show a value of Max Walk Speed of 2200, then if you release the button, press the player. will move slower The displayed value will change to 600.

run-test-project-1
While pressing the Left Shift key
run-test-project-2
While releasing the Left Shift key

Similar Posts