Start with the warm up
Worth 3 Points
What are you learning?
Unreal Engine - Movement
Why is it important?
Unreal Engine comes with standard movement but you have the ability to improve your game by modifying the movement
How do you show that you understand? What is the assignment?
Open up first person template
Check out the First Person Character Blueprint (in your blueprints folder in your content drawer)
Select event graph and review
Mouse
Movement
Jump
Gun
Now we are going to set up a way to test our speed and jumps
In your components on the top left, select Character Movement
This is where your movement logic is located
If you look to the details panel on the right, you can modify the movement of your character.
Explore these settings (check out walking, jumping)
Make sure and hit compile then play
Start your game and pick up the gun by colliding with the gun
Open Up the blueprint for the rifle and review it
Gun Blueprint
Now let's overwrite the max walk and jump speed with our own variable by opening the Event Graph on the First Person Blueprint (BP_FirstPersonCharacter)
We are going to replace the variables that are in the character movement component
To do this, drag the Character Movement Component on your event graph
This will allow us to set or get variables from the component.
Drag out from the character movement and add SetMaxWalkSpeed node
Now we will add the jump by adding the jump node
This will give you the ability to override your settings in the blueprint
Connect the output of your exec Max Walk Node to the input exec on your Jump Z Velocity
So at this point, jump velocity will be overridden after the Max Walk has been overridden
Both are set to 0.0 (remember, variables with a decimal are a float)
Click compile
Now we will create variables
In your blueprint on the left, add a variable and call it FP_MaxWalkSpeed
On the right side in the details panel, change the variable type to a float (decimals)
Click Compile
After you have compiled your blueprint, you have the ability to add a value to the default walk speed.
Set it to 500
Now we are going to create a variable with a different method.
Right click on the input of your Jump Z Velocity and select promote variable
You will now see a float variable created
Change the name to FP_MaxJumpHeight
Notice there is a new node connected
Click compile and add a max jump height of 500 to the default value
Drag your MaxWalkSpeed Variable on to your event graph and select Get Walk Speed
Connect the Variable output MaxWalkSpeed to the input on the Set Node
This overrides the max walk speed and jump velocity with the variables we created
We want this start as soon as the game is played so we need to add an event that activates these nodes when the game starts. We have used it before.... EventBeginPlay
Right Click on your event graph and add EventBeginPlay
Connect the Event BeginPlay output to the set input so that the nodes activate when the game begins and overrides the Max Walk Speed and Jump Velocity
Now let's leave a note so we can remember what we were working on in case we get busy.
Select everything we have been working on and press C to leave a comment
This is where you can leave notes for yourself or other members of the dev team
Explore this comment tool
Compile and save
In your variables, you need to click on the closed eye to make them public and editable
Click Compile
Now when you start your game and select the character, you can modify the max walk and jump.
THIS WILL NOT CHANGE YOUR BLUEPRINT
To change your blueprint, you must manually make the changes.
Changing variables during the game
In the character event graph, add mouse wheel up node and mouse wheel down node
Pressed means scrolling and released means not scrolling
Drag in your character movement
Add two Set Max Walk Speed Nodes
Connect the character movement node to the blue target
Connect output Pressed to input set on Mouse wheel up and mouse wheel down
From the character movement node pull out and search up Get Max Walk Speed
Now we need to put in the + when you scroll up and - when you scroll down
To do this, pull out a node from thee Max Walk Speed Node and put + in the search then select Add
Do the same but this time create a subtract node
Clean up the nodes so they are easy to see then change the float nodes (+&-) to 100
Then connect the outputs to their respective Max Walk Speed Inputs
What we are doing here is changing the speed up by 100 when we scroll up and down by 100 when we scroll down
Compile and play
When you play the game and scroll, your speed to increase or decrease
So once you have found the speed that you like for your game, how do you know what it is?
For this, we will use the print string like we did with the lights
Add a print screen node and connect the Execs along with the green to white
Now we can see the speed when we play the game
Do the same with thew mouse wheel down
Create a comment and make a note about what you worked on
Run Sprint Go
Click on settings at the top left
Click on project settings
Click on Input
Open up Action Mappings
Click the + to add a new action
Name the action Sprint
Click to the right of the keyboard icon and choose left shift
You can now add the action event Sprint to the Event Graph
What we are going to do is have the player increase the speed when the left shift is pressed and slow down when it is released
Add the InputAction Node Sprint
Pull the CharacterMovement node to the event graph
From the Character Movement Node, pull out TWO add a Set Max Walk Speed Nodes
Connect Pressed Exec to the input exec of the set max walk speed exec
Connect Released Exec to the input exec of the other set max walk speed exec
New let's create a duplicate MaxWalkSpeed Variable by right clicking & selecting duplicate
Change the name of the new variable to FP_MaxSprintSpeed
Click Compile and change the default value to 800
Drag both MaxWalkSpeed and MaxSprintSpeed Variables into the Event Graph
Choose GET
Connect the Max Sprint Speed node into the set node for pressed
Connect the Max Walk Speed node into the set node for Released
After you compile and play, you should be able to sprint by clicking shift
Create a new boolean variable called isSprinting and compile
Leave the isSprinting Variable as not public (eyes closed)
Add two instances of the isSprinting Variable and select SET isSprinting
Connect the outputs of the Set Max Walk Speed to the input of the iSSprinting
Mark the box isSprinting as true by clicking the box
Select all the sprinting nodes and create a comment
Crouching
We are going to make the character crouch with a speed so it takes some time to make the character crouch rather than immediately drop making it more life like.
In the first person map
Click Settings > Project settings > Engine > input
Click the + to add a new action mapping
Name the new action Crouch
Click on the + symbol on the new action map Couch
Map the first key to C
Map the second key to Left Ctrl
In the player Event Graph, add the crouch action event
From your Sprinting Nodes, select, copy and paste the following
Connect the pressed exec out from the InputAction Crouch to the top exec input on the set
Connect the released exec out from the InputAction Crouch to the bottom exec input on the set
Duplicate the FP_MaxSprintSpeed Variable and name it FP_MaxCrouchSpeed
Compile and set the default value on the right (details panel) to 200
Drag the new Max Crouch Speed Variable to the Event Graph (select get) and connect to Max Walk Speed.
Compile and play
You will see that when you press C, it is just slowing down... trust the process
In the BluePrint, open your viewport
Notice your camera is at the top of your character
Go back to the event graph
We are now going to add a timeline to make a smooth couch motion
Right click in the Event Graph and search up Add Timeline
Name it T_Crouching
Connect the Crouch Speed exec output to the Pressed exec input on the timeline
Connect the WalkSpeed exec output to the Released exec input on the timeline
So when you press the key, it plays and when you release, it reverses
Double Click on the timeline that you just added to define it
The length number is the amount of time it takes to complete the action (in this case crouching)
Change it to a half second (0.5)
Then click the +Track button and add a float track
Name it Crouch_Alpha
Now we are adding keyframes (similar to blender and premier)
Right Click at the 0 of the timeline and select Add key to CurveFloat_0
Set the time to 0.0 if it is another number
Add a second keyframe at 0.5 but this time add a value of 1.0
Select both keyframes the right click on the second keyframe and choose user
This will make the transition smoother
Click compile
There will be a new option in your Timeline Node called Crouch Alpha
This is going to be used to update the camera (player) position
Grab our first person camera from components and drag it to the Event Graph
Now we set the camera
Pull out a connection from the First Person Camera and add Set Relative Location
Connect the update output exec from your crouching timeline to the input exec in the set relative location
What is happening here is that for half a second, the location of the first person camera will be constantly updated.
We will use a LERP to go from value 1 to value 2 by dragging out the input of the New Location on the SetRelativeLocation Node
Connect the Crouch Alpha (timeline) to the LERP Alpha
Find the location by clicking on the FirstPersonCamera in components (top left side)
Copy the location on the Z Axis in the details panel
Paste the number from the Z Axis in the Z value in LERP A
This will be the starting height
Set the Z value on B to 30
Add the X and Y Values of your First Person Camera Settings into your A&B LERP
After you add the values in an compile, your player should go from your Z height in your A Lerp to the Z Height in your B Lerp
Now that we have created the LERP for the camera, we need to add the crouch functionality to the capsule for collisions as well.
Drag the Capsule Component in your Event Graph
Add a connection from Capsule Component to Set Capsule Half Height
Connect the output exec from the SetRelativeLocation to the input of Set Capsule Half Height
Add a LERP from the input of the Set Capsule Half height (green)
Connect the crouch alpha from the timeline node to the Alpha of the new LERP
Select the Capsule Component on the top left side
Copy the number from the Capsule Half Height in the details panel on the right
Add that number to the A LERP Input
Change the B LERP input to 50
Compile and play
Your capsule will now crouch
Now that you have set the capsule crouch, you no longer need the camera
Remove the First person Camera, Set RelativeLocation and LERP Nodes connected with the Camera
Connect the Update from the Crouching Timeline exec output to the input exec in Set Capsule Half Height
Compile and test
Now that crouching is working, we want to remove the the ability to sprint while crouching
In your variables, duplicate your IsSprinting Variable and change the name to isCrouching
Add two instances of the isCrouching variable in the event graph and choose set (not get)
Make the top isCrouching true
Disconnect the links going to the input exec of Crouching Timeline
Connect the true isCrouching boolean output to the input exec play in the timeline
Connect the false isCrouching boolean output to the input exec reverse in the timeline
Connect the top exec output of the walkspeed variable to the input of the true crouch boolean
Connect the bottom exec output of the walkspeed variable to the input of the false crouch boolean
Right click in the event graph and add Add Custom Event
Name your Custom Event StopCrouching
Connect the exec from the StopCrouching to the input of the false boolean Set
Add a comment box for the crouching
Time to add two branches in your sprinting comment block
Remove the connections from the exec to your InputAction Sprint
Connect the pressed exec to the input of one branch
Connect the Released exec to the input of the other branch
So if the condition iS Crouching is true, we want it to stop crouching when the sprint is pressed
Add the isCrouching (get)Booleanand connect it to the branch with the condition Pressed
From the branch connected to the IsCrouching Boolean, pull out a connection from True and add the node Stop Crouching
Connect the Stop Crouching exec output to the Set Max Walk Speed
If the player is not crouching, the condition isCriuching is false to the player can continue to the variable MaxWalkSpeed
Connect the False Output on the IsCouching exec Branch to the input exec of the variable MaxWalkSpeed
Connect the boolean IsCrouching to the condition of your second branch
Connect the false of the second branch to the exec from set walk speed
So when you are not crouching, the movement speed is updated
Compile and play
When you crouch, you will not sprint
When you stop crouching, while sprinting, it will still update the maximum movement speed
To deal with this, add a branch to the Crouch
Delete the connection from the released exec output from the InputAction Crouch and connect it to the Exec input from in the new branch
Connect the false exec from the branch to the exec input of the Set connected to MaxWalkSpeed
Add the boolean is Sprinting (Get) and connect it with the condition in the branch