Game Characters (1st, 3rd, enemy)

1st person game

Download FPS Weapon Bundle asset in epic, add in a UE 4.27 project
Create 1st person project: Blueprint, Desktop, Maximum, tick Start content
Go back to epic, launch the asset dowload ue4 project, migrate the FPS Weapon folder to the UE5 project → Content

Sprinting the 1st person character:


Open the 1st person character blueprint (in World Outliner or in Details)
Components → Character Movement → Details - >Max walk speed (default as 600)
Create Left Shift node, drag Character movement node from component, and drag the character movement output to create set max walk speed node (R click and type won’t show, except untik context sensitive):
(i.e. when hold L shift and move, the speed increase from 600 to 1500):
image.png
In 1st person character BP → Viewport, choose Mesh2P in Component →Details → Animation → Anim Class, open FirstPerson-AnimBP (or open in Content → FirstPerson → Animation)
→ Asset Details → Animation → Rate Scale (to change animation speed, here the shooting)
In FirstPerson AnimBP → New State Machine graph → duplicate FPP_Run node, rename as FPP_Sprint, open it
→ Select Play FirstPErson Run node → Details → Play rate: 1.8
Back to New State Machine graph ,connect transit back and forth arrow between FPP run and FPP sprint
In Run to Sprint transit:
create Is Sprinting variable, drag in graph, add Equal/= node, tick the box, connect as:
image.png
Repeat the same in Sprint to Run transit, but untick the equal node

Go back to Firstperson character BP, to event graph, add variable Sprinting → connect the SET variable as follow (untick one SET Sprinting) :
image.png
Go back to Anim BP, event graph → add Cast to FirstPersonCharacter node, sprinting vairable, SET is Sprinting variable. connect as follow:
(i.e. When the character is moving, and walk speed reach 1500 (hold shift), sprinting valid)
image.png

Zoom in with gun:
In Project Setting, add new buttom (name as Aim) in action mapping bidding (right mouse button)
In 1st person charcter BP, create Aim node, drag Mesh2P (in component) to the graph, create Move Component To node, set as follow
Remark: Yellow target relative location (rename as AIM Loc) is created when drag the input from move component to node, type promtoe to variable)
image.png
Duplicate the above nodes (Mesh2P and Move Componet to), add a new promote to variable, name as ORIGINAL Loc, connect to Released of Input Aim
→ Add Target Relative Rotation promote to variable, rename as Rotaion
Connect as follow:
image.png
Select Mesh2P in Component → Details, copy XYZ location
→ select ORGINAL Loc variable → Details → Default value → paste the ORIGNIAL Loc XYZ value
Go to Viewport, on Mesh2P → move the rotation and location, check instantly the view i wanted in the scene
→ Copy the location →
go to event graph → Aim Loc variable, paste the XYZ value in default
→ copy back ORIGINAL Loc variale location, paste back in Mesh2P Details
Still in Character BP event graph, change Over Time to 0.1in Move Component to nodes
→ click on Rotation node, rename as AIM Rotation
→ duplicate and rename as ORIGINAL rotation, copy Mesh2P XYZ rotation and paste here
(AIM Rotation value no need to change, should be 0,0,0)
Drag FirstPersonCamera in Compoent in event graph → add Set Field of View node
→ duplicate them, set in field value as 75 and 90:
image.png
To remove the centre cross sign in the scene when playing:
Open FirstPersonHUD BP → delete the event graph
OR
In World Setting: HUD class: None

Changing Weapons:


Open imported packed weapon set, choose KA47
Change the skeletal mesh to this in 1st person charater BP → Component → FP Gun → Details
Go to Construction Script → Change Location, Rotaion and Scale Rule from snap to Target to Keep Relative
image.png
(Or else the gun position cannot be adjusted i viewport to fit the hands holding gesture)

Put the weapon in scenes to pick up with gun BP:
In Firstperson BP folder → Create Bluleprint → Actor, name as Gun_BP, open it
In Component, add Skeleton mesh → Details →Skeletal Mesh (rename as Gun Mesh), add SK KA47
In Construction script, drag skeletal mesh in the grpah, add Set Skeletal Mesh (under Skinned Mesh),
promote to Variable from New Mesh input of Set Skeletal Mesh (name as Gun), set as public variable (click the eye icon to open eye). Connect as follow:
image.png
Drag the Gun-BP to the scene, can change other type of gun in mesh, duplicate them and replace with different gun meshes
Open Gun BP, viewport → Component, add box collision → scale the box to fit the gun size in Details
→ go down to EVENTS in details, click On Component Begin Overlap, add Cast to Firstperson character and Get FP Gun (under Default)
image.png
Go to Construction script → copy Set Sketeal mesh and Gun nodes → Paste in Event graph and connect as:
image.png

Set Auto shooting Mode:


In firstperson character BP → event grpah, Spawn Projectile →
Detach the Input Action Fire node, delete input touch node, equal and branch nodes:
image.png
and disconet montage play output node (bottom one)
image.png
Create Set timer by event (time set as 0.2, smaller value shoot faster, tick looping) and promote variable (blue) (name as Shooting timer handle), add new Costum event (red, name as Shooting), connect shooting node Montage Play input node, so finally as follow:
image.png

Drag Timer handle variable in the graph, create clear and invalidate timer by handle, connect as follow:
(to control the shooting stop when release button)
image.png
In Make Transform node, change scale to XYZ: 0.3 (reduce bullet/spawn size)
image.png
To change bullet/Spawn mesh:
Open Firstperson Projectile BP in Firstperson BP folder
or in event grpah, click the magnifier icon under Class:
image.png
In Componetn, select Projectile → Details:
Initial and max speed: 4000
Veloctiy: 4000
Projectile gravity scale: 0.4 (let the bullet not drop shortly, i.e. enhance shooting distance)

Target shooting minigame:


In First BP folder, Bluprints, create actor BP, name as Target_BP, open it
Add Cylinder in Component, rotate X 90, sacle Z 0.1 → duplicate in component, parent under 1st cylinder
→ set 2nd cylinder scale XYZ: 0.45, location Z 60
→ Change 2nd cylinder material to red material (in details)
→ Still in its details → collision preset: Overlap all → make sure Generate overlap event is ticked
→ click On Component Begin Overlap, set the graph as follow:
image.png
Go to Firstperson Projectile BP → Component → select Sphere → add Sphere Collision
→ reduce Sphere radius (in details) to fit the bullet
Remark: the sphere raidus in Sphere 1 component must be bigger than CollisionComponent sphere radius, or else it never interact.
Now the target hitted will bump the word “Hello”. To set that target explodes when hitted:
Go to Target BP → Event graph → detach Print Sting node, create follow nodes:
set simulate physics (will co-create cylinder node), do once, spawn emitter at location (set template and scale), destroy actor (duplicate), get world location
Connect as follow:
image.png
To add scores of how many target destroyed:
In Frstperson BP folder, create new BP actor, name as Target Spawner BP, open it
→ in Component, add TextRender →
Details,Alignment: Centre, text: Score, size: 40
Still in component, add arrow (4 times) → place the BP in scene, locate 4 arrows in different positions
→ In Event graph:
create “Add Custom Event” node, as name as Spawn Target,
also type “create spawn actor from class” node, choose class as Taget BP
→ drag all 5 arrows to the graph → Make Array node, add pin 4 times, Array input type “Get”,
set as follow:
image.png
Connect Event beginplay node to newly added “Spawn Target”
image.png
To fix the score and target rotation correctly (let them parallel, not prependicular to each other, revise the graph ending part as follow:
image.png
image.png
To let new target created after old one destroy, extend the graph ending part as follow (arrows location determine where new target appear):
Remark: type assign on destroy node, rename as Target destroyer
image.png
To Set Count Score:
TargetSpawn BP, Viewport, move up the Text render (name as Score), duplicate as textrender1(name as Score Number) → move it under Score, change to red color
In Construction Script:
drag Score Number in graph,
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.