UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 8

221

Having enemies flash quickly as their health decreases


Gamers require some sort of feedback each time something happens to their pawn. This can
be auditory, visual, or kinetic (controller vibrations). Most frequently the cues are visual, as
many controllers still do not support a vibration feature, however. Unreal Tournament pawns
flash red briefly each time they are hit. While UDK natively does this, why not extend that idea,
and bring back something from the NES era of gaming, wherein enemies flash red as their
health decreases, and continues to do so more quickly as it reaches zero.


Getting ready


Start by having your IDE open and ready to make some changes. We won't have to create any
new classes, but we will alter the behavior of our existing ones by adding some functions.


How to do it...



  1. Let's start by declaring the variables we'll use.
    /* Used for flashing damage as pawn's HP drops /
    var float DamageOverlayTime;
    var LinearColor DamageBodyMatColor;


These will be used to store how long the damage will flash over our pawn, along with
the color used.


  1. Let's set the values for those variables in our default properties right now:
    DefaultProperties
    {
    ....
    /* Used for flashing damage as pawn's HP drops /
    // The flash lasts this long (float)
    DamageOverlayTime=.1
    // Sets the pawn to flash red
    DamageBodyMatColor=(R=10)
    ....
    }

Free download pdf