624 Game Development and Simulation with Unreal Technology
IMPLEMENTING HIT FLASH ON ENEMY
Now, we will set up the network in blueprints responsible for showing a flash
on an enemy’s body w hen p la yer projectiles hit it.
15. Open u p the Enemy blueprin t.
16. Create a new variable called MeshMat in the Enemy event graph.
17. Change the type of this new variable to Material Interface. To do this, you
can either click on the drop -down box next to the Variable Type a nd search for
Material Interface in the search bar, or open the O bject Reference tab an d
scroll down to Material Interface (see Figure 9.54(a )).
(a) (b)
FIGURE 9.54: (a) A dding a Material Interface Variable. (b) Assigning Non-Fl ash (Regular)
Material.
18. Click on the Defaults section of the Enemy blueprint.
19. Scroll down to the Default rollout.
20. Click on the material selector next to the Mesh Mat .
21. From the drop-down menu, select and apply the same material our Enemy class
has (see Figure 9.54(b)). If you do not reme mber the material, perform the follow-
ing tasks:
a. Go to the Components tab.
b. Click o n the Enemy Mesh.
c. In the Details rollout, scroll down and find the Rendering section.
d. Expand the Materials item and see the material we applied to the element
[0].
e. Go back to the Defaults tab by clicking on it f rom the top toolbar.
f. Go to step 21 and find and apply the material.
22. Now, we will imp le ment th e network to make the Enemy shine with the Hit Flash
when hit, and turn back to its original material after a while (say a quarter of a
second).
a. Go to the event graph of the Enemy blueprint.
b. Find the network we created for the Enemy Damage Calculation ... in
step 12c on page 592.
c. Find the Branch node. Its True channel should be already connected to a
Destroy Actor node. This is because the branch tests for the Hitpoin t of
the enemy and if it is 0 or le ss, it destroys the E nemy.
d. We will use the Else channel to perform our HitFlash material swap.
A Top-Down Game with Blueprints 625
FIGURE 9.55: Switching the Mesh’s Material When Hit to Flash Material and Back to
Normal.
e. Drag a wire from the Else chan nel of the Branch node and place a Set
Material node (you have to turn off the context sensitivity).
f. Drop a copy of the EnemyMesh variable into the Ta rget channel of the
Set Material node.
g. Click on the drop-down menu on the Material channel of the Set Mate-
rial node and select the HitFlash material we created ear lier in step 12.
h. Your network should look like Figure 9.5 5.
i. Drag a wire off of the execution channel of the Set Material node and
search for and place a Dela y node. Change the Duratio n to 0.25.
j. Drag a wire off of the execution channel of th e Delay node and search for
and place another Set Mate rial on the ca nvas.
k. Drag the EnemyMesh variable onto the Target chan nel and the MeshMat
variable onto the Material channel of the Set Material node.
l. Compile and save the Enemy blueprin t.
m. Your c omplete enemy damage network with the hit flash material swap
should look similar to Figure 9.56.
IMPLEMENTING HIT FLASH ON PLAYER
Now, we will set up the network in blueprints responsible for showing a flash
when player is hit by the enemy.
626 Game Development and Simulation with Unreal Technology
FIGURE 9.56: Complete Enemy’s Material Hit Flash Blueprint Network.
23. Open up the Rotation Ch ar blueprint.
24. Create a new variable called PlayerMat in the RotationChar event graph.
25. Change the type of this new variable to Material Interface. To do this, you
can either click on the drop -down box next to the Variable Type a nd search for
Material Interface in the search bar, or open the O bject Reference tab an d
scroll down to Material Interface (see Figure 9.54(a )).
(a) (b)
FIGURE 9.57: (a) A dding a Material Interface Variable. (b) Assigning Non-Fl ash (Regular)
Material.
26. Click on the Defaults section of the RotationChar bluepr int.
27. Scroll down to the Default rollout.
28. Click on the material selector next to the PlayerMat.
29. From the dro p-down me nu select and apply the same material our RotationChar
class has (see Figure 9.54(b)).
30. Now, we will implement the network to make the Player shine with the Hit Flash
when hit by enemies, a nd turn back to its original material after a while (say a
quarter of a second).
a. Go to the event graph of the RotationChar blu eprint.
b. Find the network we created for the Dam age Calculation for Player
in step (6) on page 594.
c. Find the Branch node. Its True channel should be already connected to a
Destroy Actor node. This is because the branch tests for the Hitpoin t of
A Top-Down Game with Blueprints 627
FIGURE 9.58: Switching the Mesh’s Material When Hit to Flash Material and Back to
Normal.
the enemy and if it is 0 or less, it destroys the Enemy.
d. We will use the Else c hannel to perform our HitFlash material swap.
e. Drag a wire from the Else chan nel of the Branch node and place a Set
Material node (you have to turn off the context sensitivity).
f. Drop a copy of the EnemyMesh variable into the Ta rget channel of the
Set Material node.
g. Click on the drop-down menu on the Material channel of the Set Mate-
rial node and select the HitFlash material we created ear lier in step 12.
h. Your network so far should look like Figure 9.58.
i. Drag a wire off of the execution channel of the Set Material node and
search for and place a Dela y node. Change the Duratio n to 0.25.
j. Drag a wire off of the execution channel of th e Delay node and search for
and place another Set Mate rial on the ca nvas.
k. Drag the PlayerBody variable (or the mesh name yo u created for the body
of the player) onto the Target chan nel and the PlayerMat variable onto
the Material channel of the Set Material node.
31. Compile and save the RotationCh ar blueprint.
32. Your complete enemy damage network with the hit flash material swap should
look similar to Figur e 9.59.
628 Game Development and Simulation with Unreal Technology
FIGURE 9.59: Complete Player Material Hit Flash Blueprint Network.
What Happened in TUTORIAL 9.15. . .
This was the fina l series of tutorials to create a top-down space shooter game
from scratch. In this tu torial we implemented the final visual effects in wh ic h the
material of our enemy and player actors would switch to a glowing ember color
for a fraction of a second before changing back to the original materials, when
the player is h it by the enemy and when the enemy is hit by the projectiles. This
will give our actors the look th at they are being hit and taking damage.
To achieve this, w e utilized material interfaces. A material interface is an
object that can contain a material parameter and is exposed in-game at runtime to
our blue print program. We can use these material interfaces to make cha nges to
the materials of a static mesh or any other geometry we refere nce in the blueprint
event graph.
In our player and enemy blue prints we added the change of material logic by
setting the materials of our enemy and the player to Hit Fl ash materials when
they are hit. We switched the materials back to the no rmal materials after about
a quarter of a second. This creates the bright flashing glow on our player and
enemy actors when they are hit and take damage before going back to normal.
9.10 SUMMARY
In this cha pter we created a top-down game from scratch. We im plemented almost
all aspects of a basic game, with the exception of a HUD system. We started by
creating our own player controller, game mode and player characte r classes. We then
implemented our own projectile class for the ammunition our player will use to hit
enemies.
We imp le mented our game over logic and the functionality for our player, projectiles,
..................Content has been hidden....................

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