584 Game Development and Simulation with Unreal Technology
(a) (b)
(c)
FIGURE 9. 18: (a) Expand the C oll ision Rollout. (b) Leaving Default Response. (c) Set up
CCD.
d. When creating each collision channel, leave the Default Response in the
New Channel to Block (see Figure 9.18(b)). Note: We will not be using
the enemy channel until a later tutorial.
e. Close the Project Settings window.
5. Now, go back into the Components Editor of the Projectile blueprint.
6. Change the Collision Object Type from World Dyn amic to the newly created
PlayerProject ile ( See Figure 9.19(a)).
7. In the Collision Responses check the Ignore box for the Player and Player
Projectile so that bullets do not collide with either the player or other bullets
(See Figure 9.19(b)).
8. Compile and save the Projectiles blueprint.
SETTING UP PLAYE R’S COLLISION
9. If the RotationChar blueprint is closed, open it up.
10. Go into the Defaults tab of the RotationChar blueprint and change the Collision
Preset under the mesh to Cus tom.
11. Change the Object Type to the newly created Player from the drop-down box
(see Figure 9.20(a)).
12. Also set everything to B lock except for Visibility, Player , and PlayerProjectile.
13. Set Visibility , Player, and PlayerProjectile to Ignore ( See Figure 9.20(b)).
14. Go to the components mode of the RotationCh ar and change the collision preset
of its [ROOT]Capsule Component, as below:
A Top-Down Game with Blueprints 585
(a) (b)
FIGURE 9. 19: (a) Change Collision Type to Our Own Type. (b) Ignore Collision between
Bullets and Player - you do not want the player to be affected by his/her own projectiles.
(a) (b)
FIGURE 9.20: (a) S et player Collision Type. (b) Disable Collision for Player and Projectiles.
a. Change the Collision to Custom (see Figure 9.21(a)).
b. Set the Object Type to Player.
c. Set the Object Responses as before; Block for everything except for
Player and Player Projectile.
d. Set the Object Responses for the Player and Player Project ile to Ignore
(See Figure 9 .21(b)).
15. Compile and save the bluep rint.
FINISHING UP THE PROJECTILES
16. Set a lifetime for the Projectiles. To do so, perform the following actions:
a. Go into the Defaults tab in the Projectile blueprint. Open the blueprint if
you have closed it.
b. Set the initial life span to 3.0 (see Figure 9.22(a)). This will ensure that
bullets will automatically be destroyed after 3 seconds to prevent memory
consumption. Three (3) seconds is enough time for each projectile to reach
one side o f the map to the other before being destroyed.
17. Go back to th e Components tab of the Projectiles blueprint.
586 Game Development and Simulation with Unreal Technology
(a) (b)
FIGURE 9. 21: (a) Select Object Type. ( b) Set Collision to Ignore between Player and Pro-
jectile Actors.
(a) (b)
FIGURE 9.22: (a) Setting Projectile Lifespan. (b) Projectiles Generate Hit Event.
18. Check box that says Simulation Generates Hit Events in the Collision sec-
tion of the Details rollout (see Figure 9.22(b)). This will allow us to make things
happen when hit events occur with the projectiles.
19. We will now demonstrate this by having the bullets destroy themselves when they
collide with another object.
a. Go into the Event Graph in the Projectile blueprint.
b. Add a new Event Hit node. To this this, Right-click on the canvas and
search for the Event Hit.
c. From the execution channel (white), drag off a new no de and search fo r
Destroy Actor (see Figure 9.23).
d. The Target is conveniently already set to self to destroy the projectile
itself. This works since this is being called within th e Projectile bluepr int.
20. Compile and save yo ur blu eprint.
What Happened in TUTORIAL 9.6. . .
A Top-Down Game with Blueprints 587
FIGURE 9.23: Destroy Projectile on E vent Hit.
In this tutorial we established our collision system. This is a very important part,
since the collision system will create a mechanism for us to be able to detect
when hit events occur.
We will use these hit events for the player to detect when he is hit by the
enemy to activate a damage functionality. The same logic goes for the enemy’s
collision events.
The projectiles’ collision system will also let us detect when th ey hit a wall or
an enemy. We will use these events to decide to cast damage on the enemy and
to destroy the projectiles, when they hit an object.
We first established three co llision object ch annels in the Coll ision cate-
gory of our Project Settings. This will help later on to assign these channels
as presets when we wish to establish collisions in our cla ss blueprints, and to
streamline the process.
After setting our collision system up for the player and the projectile class, we
perfor med one last mod ifica tion to the p rojectile class. This modification allows
the pr ojectile objects to simulate hit events. We use these hit events to damage
the enemy and to de stroy the projectile when it hits an enemy or a wall.
9.6 CREATING THE ENEMY CLASS AND IMPLEMENTIN G
DAMAGE
Now that our play er interac tions and the projectiles are created, it is time to shift
our focus to another equally important aspect of the game th e enem y. In th e next
few set of tutorials, we will go over the enemy class and populate it w ith the needed
functionality, both in terms of taking damage from being hit and casting damage to
the player.
588 Game Development and Simulation with Unreal Technology
FIND ON THE WEBSITE
To find updates to this tutorial and upda te d instructions about its implementa-
tion on othe r UE4 versions, p le ase visit the books companion Website at:
http://www.RVRLAB.com/UE4Book/
TUTORIAL 9.7 The Enemy Class and Damage Implementation
In this tutorial we will create the enemy class, assign its basic components and
establish its collision system .
(a) (b)
FIGURE 9.24: (a) The Enemy Class is Based on Character Class. (b) Adding Enemy Com-
ponents.
CREATING TH E ENEMY CLASS BLUEPRINT
1. Create a new Class Blueprint based on the Character type (see Figu re 9.24(a)).
2. Name th is blueprint Enemy.
3. Drag the Shape_Cube shap e from the Shapes folder of the content browser into
the component area of th e newly created Enemy blueprint.
4. Rename the cube mesh E nemyMesh (Figure 9.24(b)).
5. Add a material of your choice to your enemy.
a. Remember to do this, click on the Enem yBox mesh you just added to the
Components of your Enemy blueprint.
b. Go to the Rendering section in the Details rollout.
c. Click the + sign next to the Materials.
d. Either drag a material from the content browser in to the Ma terials[0] or
click on the search icon (the magnifying glass) and look up a suitable mate-
rial to app ly to this mesh.
6. Still in the Components tab o f the Enemy blueprin t, click on the
..................Content has been hidden....................

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