Udemy: Unreal Engine 5 Beginner Blueprints: Make your first game!: Project setup and player character mechanics - jgoffeney/Cesium4Unreal GitHub Wiki

Back

The game project is using the First Person template with blueprints and starter content.

Intro to Blueprints

Hovering over a link and pressing Alt will delete the link which using Crtl will grab the link at which ever end it closer to the mouse click.

By selecting several node you can right click and choose Alignment to automatically clean up the layout by picking an option. You can also choose Create Comment From Selection to group the selected nodes in a box and add a comment label to it to specify the functionality or whatever you like.

Cntl-W is the Unreal specific hotkey for duplicating a selection.

Hello World

The level blueprint is opened and a simple graph is created by using a 1 key event with it Pressed pin going to a Print String node.

Cleaning Up

The example game being created is not a shooter so it does not need the default objects like a gun and a cross hair. In the viewport for the FirstPersonCharacter everything was deleted except the camera and capsule. Then the camera is moved so the front is about in the middle of the capsule width.

Then within the event graph for the same object we need to delete the gun related (as shown by the blueprint compiler) Spawn projectile and If HMD and Motion Controllers... (the latter is actually for VR so removing the whole thing would be a problem if the game was still VR). Then in the construction script graph remove the AttachCompononentToComponent node which attached the gun to the character on start up.

To remove the crosshair go to the FirstPersonHUD blueprint and open it. Within the event graph immediately a graph for Draw crosshair in center of screen. Delete it.

Adding Sprint

To add a run button we need to update FirstPersonCharacter. But first we need to add a new Action Mapping in Project Settings->Engine->Input, name it Sprint and set it to the left shift key. Go to the FirstPersonCharacter event graph and add the Sprint node. From the components tab drag in Character Movement to the event graph to make a reference node to access its variables. For to run the key press sets the MaxWalkSpeed to 1000.0 and on release resets it to 600.0.

Sprint

Tuning Player Movement

The default character motion can feel floaty. To adjust it go to the FirstPersonCharacter->Character Movement.

  • CHARACTER MOVEMENT (GENERAL SETTINGS)
    • Adjust the Gravity Scale to 2.8 for a better feel
    • Increase Max Acceleration to 10000 for faster transition from walking to running.
  • CHARACTER MOVEMENT (JUMPING/FALLING)
    • For Jump Z Velocity set to 900 to compensate for the increase in Gravity Scale for jump height.
    • Set Air Control to 0.3 to allow for a little movement control while in the air for a gamey feeling.

Adding Head Bobbing

Create a new blueprint with the MatineeCameraShake base class (and name it WalkShake) and open it. We are not creating any new graphs for it but adjusting its variables.

  • OSCILLATION
    • Set Oscillation Duration to a very high value to ensure it lasts for the entire time someone is walking.
    • Set Oscillation Blend In Time and Oscillation Blend Out Time to 0.3.
    • Loc Oscillation
      • Y
        • Set Amplitude to 5.0 and Frequency to 7.0
      • Z
        • Set Amplitude to 5.0 and Frequency to 15.0, and Initial Offset to Zero

Open FirstPersonCharacter blueprint and create a graph.

  • Add event Tick. We will come back to it.
  • Add GetVelocity node and on its output pin right click and select Split Struct Pin will which take the Vector output pin and convert it into separate X, Y and Z outputs.
  • For both of the X and Y outputs create Greater and Less nodes with comparison values of 50 and -50 respectively. This checks if the player velocity in the ground plane is moving fast enough to trigger the head shake in the forward or backward direction.
  • Add OR Boolean and use the Add Pin button to add 2 more input pins and hook up all the previous comparison nodes.
  • Add IsMovingOnTheGround adds a reference to CharacterMovement and the function IsMovingOnTheGround to check if the character is indeed on the ground to ensure head shake is off when jumping or falling.
  • Add AND Boolean and connect the outputs of OR and IsMovingOnTheGround so the character has to be moving over a given velocity and in contact with the ground.
  • Off the Event Tick exec pin add a Branch node which acts as a programing if statement. Connect the And output to the Branch input.
  • From Branch True pin create a Sequence node. Create a separate Sequence for the False pin. A Sequence executes its output pins in order.
  • From the Then 0 pins of each of the Sequence nodes create a Do Once node. A Do Once node will only allow the nodes from its output pin to be performed once (until it is reset). This is a way to toggle head shake on and off for the above velocity/ground conditions instead of trying to do it every frame. From the Then 1 pin of each Sequence hook up to its opposite Do Once Reset. When one sequence completes its Then 0 / Do Once connected nodes then they are disabled but the other sequence is enabled. When head shake starts it stays running with an option to try to keep turning it on but the option to switch it off is enabled.
  • Create a Get Player Camera Manager node. This gets a reference to the player camera so we can make it shake. From the return value create the node StartCameraShake and connect its exec pin to the output pin of the top Do Once. Repeat this for StopCameraShape and connect it to the bottom Do Once. Connect the StartCameraShake return pin to the StopCameraShake ShakeInstance input. The former is creating the shake instance so the latter need to have the reference to shut it off. On the StartCameraShake Shake Class parameter select WalkShake (the blueprint we previously created) as the option. On StopCameraShake uncheck the Immediately box to prevent the camera from instantly snapping back into place.

HeadShake

Adding Sound Effects

  • Download the sounds and drag them into a new folder called Sounds.

  • Open FootstepSound and check Sound->Looping to ensure the walking sounds repeats as long as the character is walking.

Landing Sounds

  • Open the FirstPersonCharacter Event Graph.
    • Add a new event EventOnLanded.
    • Add a Switch On Int node from the event exec output and add another pin. Then drag out from Selection 0 and add a RandomInteger with the Max set to 2. We have two different landing sounds so this randomly picks which one plays. From each of the output pins add a PlaySound2d node and set Sound to each of the landing sounds and set Volume Multiplier to 0.4. For Pitch Multiplier drag out from one of the PlaySound2d nodes and then add a RandomFloatInRange node with a Min value of 0.7 and a Max value of 1.3. Connect the Pitch Multiplier of the other PlaySound2d to the return of the same random number generator. This varies the volume of the landing randomly each time.

LandingSounds

Walking Sounds

  • Open the FirstPersonCharacter Viewport and add an Audio components which is FootstepSound by default. Move the audio object near the base of the capsule for the player's feet. On playing it is just continuously playing the sound.
  • The walking sound will be tied to the Camera Shake from before.
    • Selecting Attenuation->Override Attenuation brings up two spheres with the inner sphere volume as the space where the full sound is heard and the outer sphere is the drop off region with any point outside it being unable to hear the sound.
    • Under Attenuation (Volume) you can adjust the spheres so make the Inner Radius to just contain the camera and the Falloff Distance to around 400. Then set Attenuation Function to Natural Sound.
    • Under Attenuation (Spatialization) set Spatialization Method to Binaural.
  • Now open the Event Graph and go to the HeadShake graph.
    • At the end of the graph create a GetFootstepSound node (or drag in the object from the Components panel).
    • From the output create two SetVolumeMultiplier nodes and connect the input exec pins of each to Start Camera Shake and Stop Camera Shake nodes. For the former SetVolumeMultiplier node set the New Volume Multiplier variable to 1 and for the other set it to 0. When the camera shakes you hear the sound and when it stop so does the sound.

HeadShakeWithSound

  • The running sound will be a sped up version of the walking sound.
    • Go to the Sprint graph and drag in a FootstepSound component and from its return pin create two SetPitchMultiplier nodes. Connect the output exec pins of the existing Set nodes to each.
    • For the SetPitchMultiplier node connect to the Set for speeding up the movement set the New Pitch Multiplier to 1.3 and for the other set it to 1.0. So when the character is running it sounds a little faster and higher and the other just returns it to normal.

SprintWithSound