The player does not yet have a means to defend himself. We will equip the player with a very useful and interesting way, of doing so called magic spells. Magic spells will be used by the player to affect monsters nearby.
Practically, spells will be a combination of a particle system with an area of effect represented by a bounding volume. The bounding volume is checked for contained actors in each frame. When an actor is within the bounding volume of a spell, then that actor is affected by that spell.
The following is a screenshot of the blizzard and force field spells, with their bounding volumes highlighted in orange:
Visualization of the blizzard spell can be seen at the right, with a long, box-shaped bounding volume. Visualization of the force field spell, with a spherical bounding volume, for pushing monsters away, is shown in the following screenshot:
In each frame, the bounding volume is checked for contained actors. Any actor contained in the spell's bounding volume is going to be affected by that spell for that frame only. If the actor moves outside the spell's bounding volume, the actor will no longer be affected by that spell. Remember, the spell's particle system is a visualization only; the particles themselves are not what will affect game actors. The PickupItem
class we created in Chapter 8, Actors and Pawns can be used to allow the player to pick up items representing the spells. We will extend the PickupItem
class and attach the blueprint of a spell to cast each PickupItem
. Clicking on a spell's widget from the HUD will cast it. The interface will look something like this:
We'll begin the chapter by describing how to create our own particle systems. We'll then move on to wrap up the particle emitter into a Spell
class, and write a CastSpell()
function for the avatar to be able to actually cast spells.
First, we need a place to put all our snazzy effects. In your Content Browser tab, right-click on the Game root and create a new folder called ParticleSystems. Right-click on that new folder, and select New Asset | Particle System, as shown in the following screenshot:
See this Unreal Engine 4 Particle Systems guide for information on how unreal particle emitters work: https://www.youtube.com/watch?v=OXK2Xbd7D9w&index=1&list=PLZlv_N0_O1gYDLyB3LVfjYIcbBe8NqR8t.
Double-click on the NewParticleSystem icon that appears, as shown in the following screenshot:
You will be in Cascade, the particle editor. A description of the environment is shown in the following screenshot:
There are several different panes here, each of which shows different information. They are as follows:
The default particle emitter emits crosshair-like shapes. We want to change that to something more interesting. Click on the yellow Required box under Emitters panel, then under Material in the Details panel, type particles
. A list of all the available particle materials will pop up. Choose m_flare_01 option to create our first particle system, as shown in the following screenshot:
Now, let's change the behavior of the particle system. Click on the Color Over Life entry under the Emitters pane. The Details pane at the bottom shows the information about the different parameters, as shown in the following screenshot:
In the Details pane of Color Over Life entry, I increased X, but not Y and not Z. This gives the particle system a reddish glow. (X is red, Y is green, and Z is blue).
Instead of editing the raw numbers, however, you can actually change the particle color more visually. If you click on the greenish zigzag button beside the Color Over Life entry, you will see the graph for Color Over Life displayed in the Curve Editor tab, as shown in the following screenshot:
We can now change the Color Over Life parameters. The graph in the Curve Editor tab displays the emitted color versus the amount of time the particle has been alive. You can adjust the values by dragging the points around. Pressing Ctrl + left mouse button adds a new point to a line:
You can play around with the particle emitter settings to create your own spell visualizations.
At this point, we should rename our particle system, from NewParticle System to something more descriptive. Let's rename it P_Blizzard. You can rename your particle system by simply clicking on it and pressing F2.
We will tweak some of the settings to get a blizzard particle effect spell. Perform the following steps:
3.138.123.106