Game Characters (1st, 3rd, enemy)

3rd person game (ch 7-13)

7.Player Controller Setup (separate BP character from BP controller, different way from offical UE


Open BP_Controller → Event Graph → +Add 1st Graph, name as Jumping
Create “Input jump” and “Get Player character” x2 nodes
→ also create Jump and Stop Jumping nodes, connect as follow:
image.png
Highlight all nodes → Click C (create a Comment box), name as Jumping
Add 2nd graph, name as Mouse Input
→ create 2 nodes “InputAxis lookup pitch and turn yaw (pitch and yaw naming helps to find nodes here easier, if named it in Binding in ch.2)
Create And controller pitch input and get player pawn x2 → also add controller yaw input node,
connect as follow :
Remark: target on controller input has to connect player pawn to make it work. It’s extra step needed when separate BP character from BP control.
image.png
Highlight and comment as Mouse Controls
Add 3rd graph, name as Crouching
→ create 4 nodes, Get Player character x2, Crouch and Uncrouch (turn off Context Sensitive):
image.png
Save and open BP_Animation → Set Variables graph:
Create these 3 nodes and connect as follow to Is Cruching SET node:
image.png
Add 4th Node, name as Movement
Create Input MoveForward/ForewardMotion (depend how it names in ch.2) and Rightmotion nodes
→ Create get player pawn and add movement input, duplicate them x2
→ Add get control rotation (Target is Controller) and Break rotator (to split rotation to 3 xyz values) and make rotator and get forward vector (to connect to world direction, only as Z (Yaw) value, X and Y remain 0
image.png
Duplicate control rotaion, break rotator, make rotator, and add get Right Vector (instead of forward vector), connect to RightMotion one:
image.png
Comment as Movement
Add 5th Graph, name as Gamepad Input
Create Input (gamepad) yaw and pitch node
→ add Get player pawn, add controller pitch Input, multiply
→ In Variables, add 2 float variables as follow:
image.png
In their Details (R side)→ Default Value → Base Turn Rate, set as 45 for both
Click “Add pin” in multiply node, drag BaseLookup Rate variable and connect them
→ Add Get World Delat second nodes, connect to multiple node:
image.png
Duplicate the newly created nodes and paste for Input Turnrate Yaw node, except replace add controller pitch input to yaw input:
image.png

8. Game Mode Setup

Open BP_Gamemode created in ch.1 →Event Graph → Details
→ Classes:
Player controller class: BP_Contoller
Default Pawn class: BP_character
In World Settings → GameMode Override: BP_GameMode
To set the designed game mode as default (i.e. everytime start play button, it’s on that game mode, even in world settings GameMode override set as none:
Project Setting → Project → Maps & Modes → default gamemode: BP_gamemode

9. Double Jump for the character


Open BP_Character → Components, choose BP_character (self)
→ Details → Character → Jump Max count: set to 2

10. Adding Footsteps Sound


Content Broswer, R click → Sound → sound cue, name as FC_footstep, open
Import WAV format foostep files in Content Broswer → drag them in Sound Cue event graph
Create Random node, add input (depends on how many footstep files need to add (when sound is play, the random nodes select the cue randomly)
Select Output node in graph → Sound → Volume and Pitch Multiplier (set their value higher if needed)
image.png
Open character animation → Choose running/walk animation in Asset Broswer → Stretch the timeline and drag to the point the foot just step on ground → R click on the row “1”→ Add Notify → Play Sound (a keyframe is created)
image.png
Select “play sound” keyframe → Details → Sound, choose SC_footstep sound cue
Move the timeline to next step the foot on the ground, copy the previous keyframe, R click → Paste
image.png
Repeat the same for other animation

Simple Hit Damage (physics)


Add a cube in scene, select it
Blueprints (top L corner) → Convert Selection to Blueprint, name as BP_cube0, New Subclass, Staticmeshactor, open it
image.png
In Component, select Static Mesh Component → Details
→ Collision:
Can Character Step on: No
Collision Preset: Trigger
Select the Mesh in component, Go to Event Graph → R click, unfold the following and choose Add on component begin overlap (a node created)
image.png
Created Apply Damage (under game) node, Base damage set to 10, connect as follow:
image.png
Open BP_character → Event Graph → Add Graph, name as Damage
→ in Damage graph, create Event Any Damage (under game)
→ Add variable, name as Health, set as Float → set Health default value as 100 (in Details)
Back to main event graph in BP_character, drag health variable, and add Delay (set duration as 1sec), Print String nodes, connect as follows (to print out health value after damage):
image.png
Go to Damage graph in chracter BP, create Subtract node, clamp (float) node (optional, a value between upper and lower bound) and drag Health (both get and set) in graph, connect as follow (i.e. take current health, subtract the damage amount, the new value go to SET new health value):
image.png

12. Punching or Attack


Open Character animation → In Asset Detail -< Root Animation, untick Enable RootMotion
R click the punch animation → Create → Create AnimMontage, name as MN_punch
Open BP_animation → Animgraph
→ Create Slot (under Montage), connect in between:
image.png
Open BP_controller → add Graph, name as punching → open it, set as follow (i.e. use controller to trigger montage, while in montage, disable player movement, afterward back to movement. While playing montage, we check if the character is falling or in air):
image.png
Remark: target mesh blue node, types get mesh,
montage to play select BP_punch created earlier on, play rate can be up to 1.2,
target character movement blue node, types get character movement

Health Bar setting:


In Content Broswer, R click → User Interface → Widget Blueprint, name as WG_HUD → open
In Palette (top L corner), Drag Progress Bar in the frame→
Details →
Progress: Precent: 0.5
Appearance: Fill color (optional)
Next to Precent → Bind → create binding (a event graph is opened called Get Precent0, rename as GetHealth)
image.png
Open the BP_Character, check and be sure the Health variable is float, with default value as 100
Open event grpah in WG_HUD, create the following graph
image.png
Remark: the blue SET node created when click “promote to variable” after drag out As BP_character output
image.png
Back to GetHealth graph, drag As BP Character from variables to the graph (Get), create get Health node,
Create following graph:
image.png
Open BP_character → Event Graph, create Get Widget node (it’s shown as Construct None in graph), select its class as WG_HUD,
connect the Event Beginplay node:
image.png

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.