Using Take Damage events to produce explosions

In this recipe we'll introduce an event that allows you to fire off actions when an actor happens to take damage from the player or from a Bot. This lesson will also cover how to add particle emitters to the event to generate explosions. Rather than use many particle emitters we'll teleport a single emitter from place to place whenever it is needed.

Getting ready

Open Packt_04_Explosions_Start.UDK or continue from where you were in the previous recipe if you completed it. In this map the Bot handling is already set up, from previous recipes.

How to do it...

  1. In the map are four glowing white spheres. In gameplay, they are exposed in order by touching one after the other. Each of these is represented in Kismet by an Object Variable. These are indicated as KActor_0 to KActor_4. Locate the Object Variable KActor_0 in the commented section Collect All Four Orbs. Right-click on it and choose Select KActor_0 in level.
  2. In the section commented Initial Conditions, the other KActor's are clustered together. Hold Ctrl and click them in series to select all four variables, then right-click and choose Select Actors in Level.
  3. In some clear space in Kismet, right-click and choose New Events using KActor_0... | Take Damage. This will add a Take Damage event for each actor. With all these selected, change their Max Trigger Count properties from 1 to 0. This means they can be damaged more any number of times.
  4. Set the Re Trigger Delay property below it to 3.0 seconds, to slow down the event's availability.
  5. Hold D and click to add a Delay. Give it a Duration of 0.3. Hook up the KActor_0 Take Damage event's Out nub to the Start nub of the Delay.
  6. Right-click on the Out nub of the KActor_0 Take Damage event and choose Copy Connections. Go to each Out nub of the other Take Damage events and right-click and choose Paste Connections. This is a handy way of duplicating links to actions. In other situations you can transfer links by using Cut Connections. What you should have now is all the events feeding into the same Delay action's Start.
  7. Next, hold T and click to add a Toggle action. Hook the Finished nub of the Delay into the Turn On nub of the Toggle.
    How to do it...
  8. Now we'll add the particle effect to the scene. In the Content Browser, search for the ParticleSystem WP_ShockRifle.Particles.P_WP_ShockRifle_Explo. Drag it into the scene where the white sphere KActor_0 sits. You'll have to scale it to suit the size of the sphere, down to about 0.6 DrawScale 3D.
  9. With the Emitter selected, press F4, and expand the property Emitter | Particle System Component | Particle System Component to locate Auto Activate. Turn this off. We only want the particle to activate when we tell it to in Kismet, otherwise it would just fire off once when the game starts and that would be all.
  10. In Kismet, right-click on the Target nub of the Toggle you added and choose Assign Emitter_0 to Object Variable(s). What we now have is this: whenever one of the KActor spheres takes damage then the particle will activate, making a brief explosion. However, currently it will always occur at the same location. So, let's make sure it gets teleported where we need it at the appropriate time.
  11. In the section called Collect All Four Orbs locate the Trigger_0 Touch event. Coming from its Touched nub is a Toggle T1 which Turns On the next event. Send an additional wire from the red Event nub of the Toggle T1 to make a Dynamic Binding Event to the top label of the KActor_1 Take Damage. Likewise, send an additional wire from the red Event nub of the Toggle T2 to the top label of the KActor_2 Take Damage. Do the same from Toggle T3 to KActor_3 Take Damage. This means the events we've added can't fire in the wrong order. The following is what you should finally have for the Take Damage comment block shown below, including the enabling of the events by the Toggle T1, T2, and T3:
    How to do it...
  12. Near the Trigger_0 Touch event right-click and choose New Action | Actor | Teleport. Hook the Touched nub of the Trigger_0 Touch event to the In nub of the Teleport action. Set Object Variable Emitter_0 as the Target. Select the Teleport action and the assigned Object Variable for the Target and press Ctrl + C. Set for the Object Variable KActor_1 the Destination nub of the Teleport action. Press Ctrl + V to paste what you copied previously. For the pasted action, connect its In nub to the Trigger_1 Touch event's Touched nub. For the Destination, set the Object Variable KActor_2. Paste again, and for the second pasted action, connect its In nub to the Trigger_2 Touch event's Touched nub. For the Destination, set the Object Variable KActor_3.
    How to do it...
  13. Select the four Trigger Touch events and in their properties expand the Touch Types category. Here, look for Ignored Class Proximity Types and add an entry [ How to do it... ] and in the [ 0 ] channel choose UTWeap_RocketLauncher_Content from the list. This prevents the rockets we fire causing a touch event on the Triggers that are supposed to be touched by the player.
  14. What we have now is that each time the available Trigger Touch event is touched, the Emitter in the scene jumps to the location of the next exposed white sphere. PIE and shoot at the spheres to see if the Emitter fires off a purple flashy explosion at the right location. The Rocket Launcher will also produce a radius-based explosion, which is built into the weapon.
  15. Last of all, to give some contextual meaning to shooting at the orbs, as opposed to just collecting them, let's reload the player's rocket launcher each time the player shoots at and hits an orb. Go to the section commented Take Damage Events and hook up all the Take Damage events into a New Action | Pawn | Give Inventory action. We've set up this before, so you'll find it easy to add the Player 0 Variable to the Target of the action, and then in the properties of the Give Inventory action add an entry to the Inventory List [ How to do it... ] and in the [ 0 ] channel select UTWeap_RocketLauncher_Content. PIE and shoot the orbs and you should notice that your ammo doesn't deplete unless you miss the orbs.

How it works

The particle system fires off when the level loads by default—this is to allow looping effects such as smoky chimneys, or leaves blowing in the wind, to run continually. For explosions, you want to turn off Auto Activate and instead use a Toggle action to fire them. In this example, it's it's better to use one Emitter instead of four. We can Teleport it to where it's needed through the Trigger Touch events that hide and expose the orbs. It's much cheaper to set up a Kismet network than to add four emitters. The calculation time for this is negligible at run-time.

The Take Damage events have been added to each sphere to let the Emitter fire. Also, we've added a Give Inventory action to reload the player's rocket launcher. It's good to match a visual effect with some kind of result that affects the player. It gives us a justification to shoot the orbs, and means we won't be likely to run out of ammo by the time we shoot at the exposed Bot. We can also add sound to round off the explosion.

An example is provided in Packt_04_TakeDamage_DEMO.UDK.

How it works
..................Content has been hidden....................

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