A Top-Down Game with Blueprints 599
(a) (b)
FIGURE 9.32: (a) Level Blueprint. (b) When Character is Destroyed by Means of On De-
stroyed Event.
FIGURE 9.33: The Game over Cut-Scene Network.
8. Drag your RotationChar character you created onto the level.
9. Select your RotationChar in the level by clicking on it.
10. With the RotationChar still selected, go back to the Level Blueprint. Right-
click on the canvas of the Event Graph and search for a new node called On
Destroyed. This is an Event node, and therefor e looks red.
11. Place the On Destroyed event below the GameOver Ca m era reference (see
Figure 9.32(b)).
12. Since you had the RotationChar selected when creating this node, you will no-
tice th at it now triggered when the actor is destroyed.
13. Create a new node called Get Player Controller above the GameOver Camera
referenc e on the canvas.
14. From the execution channel of the On Destroyed node drag off a Print String
node and have it output Game Over!!!.
15. From this no de, dr ag off a new one c alled Set View Target With B lend. Note
that you may have to turn context sensitivity off to find this node.
600 Game Development and Simulation with Unreal Technology
16. Connect the return value of the G et Player Controller to the Target of the Set
View Target with Blend.
17. Connect the return value of the GameOver Camera re ference to the New Vi ew
Target.
18. Change the Ble nd Func to VTBlend Cubic and set th e blend time to 0.25.
19. From the set view target with blend, drag off a delay node with a duration of 5.0 .
20. From that Delay node, drag off a Open Level node and type in your level name
in the Level Name box.
21. Finally from the Open Level node drag off another Print String node that out-
puts Reloading level....
22. You can comment a ll these as Gameover and Reloading Level ( see Fig-
ure 9.33).
23. Compile and save yo ur blu eprint.
What Happened in TUTORIAL 9.10. . .
With the logic for our player, enemy, and projectile’s damage implemented, we
need to have a mecha nism to declare game over. We will also need to visually
convey the end-game to the players attention through a cut-scene.
In this tutorial we implemented the end game and game over cinematic. We
first created a second camera to change our view fr om the top-down view of the
player to the gam e-over view. This view will have a wider angle and looks at
the player in a wider area of the level. Later on, wh en we implement the visual
effects for the player’s death sequence with fires and smoke, this view will be
pretty interesting.
To cut to the new camera, we looked for an event on the play er character’s
class called onDestroyed. When a player’s health reaches zero, form the dam-
age logic we had called a Destro y Actor function to destroy the player. Once
this happens, the onDestroyed event will fire. When the event fires, we will cut
to the game over camera, stay there for 5 minutes an d restart the level.
9.8 AI AND ENEMY SPAWNING
We have been making great progress so far in establishing our level, designing our
character, projectiles, and enemy classes and implementing the damage functional-
ities. However, our game is nowhere close to being p la yable. For one thing, our
enemies are going to be q uite static if we place them in the game.
This is because we do not have a mechanism in place fo r our enemy to play the
game. That requir es Artificial Intelligence (AI). The A I we will e stablish in this level
is going to be quite simple. In fact, it will be so simple that only on e beh avior could
describe it. T hat behavior is the seeking behavior. We will implement this behavior
in such a way that our enemy instances c ould detect the p la yer and try to chase him.
A Top-Down Game with Blueprints 601
The nice thing about implementing the chasing behavior is that it is simple enough
for us to be able to program it quickly. T his simplicity fits well with the limited
number of pages we have to describe the AI im plementation. However, the chasing
behavior is visually c omplicated enough to give us a nice competitive en emy class.
But before we get into the details about implementation of our AI, we first need to
be able to spawn enemies insid e our level. This is wha t we will tackle in the next
tutorial.
9.8.1 SPAWNING ENEMIES
The first item for us to implement to pin the pla yer and enemies against each other is
to sp awn the enemy in the level.
FIND ON THE WEBSITE
To find updates to this tutorial and u pdated instructions about its implementa-
tion on other UE 4 versions, please visit the books companion Website at:
http://www.RVRLAB.com/UE4Book/
TUTORIAL 9.11 Spawning Enemies
In this tutorial we will implement the spawnin g functionalities in our game in
such a way that one enemy will be spawned at a certain interval from a randomly
selected spawn base.
PLACING EN EMY BASE S
To spawn the enemies in the level, we will first e stablish certain loca tions in our
map (e.g., each corner) as a spawn point. We will, first, place a spawn base (a
static mesh to visualize it) in each corner of the level.
1. We want to drag 4 prop objects from the starter content into the 4 corners of our
map as enemy bases. Our enemies are going to spawn off of these bases.
2. From the content browser, open the Props folder and place 4 of the
SM_MatPreviewMesh_02 into the 4 corners of our map.
3. Rotate the bases so they are facing the center of the map.
4. Rename those objects TopLef t, TopRi ght, BottomLeft, and BottomRight.
5. Your map should look like Figure 9.34.
6. This is primarily to keep track of them in the level blueprint as we will be making
referenc es to th em shortly.
602 Game Development and Simulation with Unreal Technology
FIGURE 9.34: Placing Enemy Spawn Bases in the Level.
SETTING UP SPAWN INTERVALS
Next, we will need to establish a mechanism for our spawning functionality to
take place at a certain interval. This is th e task we will tackle n ext.
7. Open the Level Blueprint.
8. Create a new public variable called EnemyToSpawn. This variable is going to
be of ty pe Class and mu st be searched for manually.
9. To assign the variable typ e, use the dr op-down box of the Variable Type and in
the search box type Enemy (or any name you gave to your enemy class) that is
color c oded PURPLE.
10. Compile the blueprint and then in the Default Value section of the Details roll-
out use the drop-down box to select Enemy (see Figure 9.35).
11. Now, create a new Ev ent Begin Play node in the Event Graph of the Level
Blueprint.
12. Right-cl ick below the Event Begin Play node and create a Custom Event.
Note: You may need to make sure that the Context Sens itive checkbox is
checked.
13. Rename the Custom Event to Spawn Enemies.
14. Right-cl ick to the right of Event Begin Play and search for and add a Set
A Top-Down Game with Blueprints 603
FIGURE 9.35: Creating a Variable for the E nemy to Spawn.
Time Delegate node.
15. Connect execution ch annels from both the Event Begin Play and Spawn
Enemies Custom Event nodes to the input execution channel of the Timer
Delegate node.
16. Then connect the r ed output channel of the Spawn Enemies custo m even t into
the Delegate c hannel of the Set Timer Delegate node.
17. Set the Time Value to 3.0.
18. Your network should look like the left portio n of Figure 9.36 so far.
19. From the execution cha nnel of the Set Timer Delegate output channe l, drag off
and search for Spawn AI from Class node.
20. Drag the EnemyToSpawn variable you created earlier and drop it into the Pawn
Class channel of the S pawn AI from Class node (see Figure 9 .36).
SPAWNING ENEMIES FINAL IMPLEMENTATION
Now that we have our ba sic requisites set up for the functionality to spawn the
enemies, we need to calculate the spawn locations at which each enemy will be
spawned. Th e next few steps will guid e us through creating this mechanism.
..................Content has been hidden....................

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