Breaking down the Character Movement

Let's begin by opening the FirstPersonCharacter Blueprint, located in the same Blueprints folder as CylinderTarget_Blueprint from Chapter 5Object Interaction with Blueprints. Find FirstPersonCharacter in Content Browser and double-click on the Blueprint. You will open Event Graph and see a large series of Blueprint nodes. The first group of nodes we will look at is bounded by the Event Graph comment labeled Stick input, as shown here:

The red trigger nodes are triggered at every frame and pass the values of TurnRate and LookUpRate from a controller input. These values are most commonly mapped to the left/right and up/down axis triggers of an analog stick. Note that there are only two axis triggers. Detecting a look down or a turn left Event is covered by these very nodes and is represented as a negative number in Axis Value that is passed.

Then, the values from the two axis triggers are each multiplied by a variable, representing the base rate at which the player is intended to be able to turn around or look up or down. The values are also multiplied by the world delta seconds to normalize against varying frame rates, in spite of the triggers being called every frame. The value resulting from multiplying all the three inputs is then passed to the Add Controller Pitch Input and Add Controller Yaw Input Functions. These are the Functions that add translations between the controller input and the effect on the player camera.

Below the Stick input group of Blueprint nodes, there is another comment block, called Mouse input, and it looks quite similar to the Stick input group. Mouse input converts input from mouse movements (as opposed to controller axis sticks) into data, and then passes those values directly to the corresponding camera yaw and pitch input Functions, without needing the same kind of calculations that are necessary for analog input.

Now, let's look at the group of nodes that manage player movement, as shown in this screenshot:

The Select nodes test whether the player is using a virtual reality head-mounted display (VR HMD). If a VR HMD is enabled, then the vectors used are from FirstPerson Camera; if it isn't, then the vectors used are from the Actor root Component.

Functionally, the other nodes are set up similarly to the Stick input and Mouse input groups. The axis value is taken from the forward and right movement axis inputs on a controller or keyboard. Again, these nodes represent backward and left movements as well, in the form of negative values for the Axis Value outputs. The significant difference in movement translation is that we require the direction that the Actor is going to be moved in, so that the degree of movement can be applied in the correct direction. The direction is pulled from the Get Actor Vector nodes (both forward and right) and attached to the World Direction input of the Add Movement Input nodes.

The last movement-related group of nodes to look at is the node group contained within the comment block labeled Jump. This group is simply made up of a trigger node that detects the pressing and releasing of the key mapped to jumping and applies the Jump Function from when the button is pressed until it is released.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset