UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 6

177

;--------------------------------------------------------
.Bindings=(Name="GBA_ToggleFlashlight"
,Command="ToggleFlashlight")
.Bindings=(Name="X" ,Command="GBA_ToggleFlashlight")

The first line is setting our ToggleFlashlight function to the name GBA_
ToggleFlashlight and the next line is binding our GBA_ToggleFlashlight
command to the X key.


  1. Rebuild scripts and hop into the game. Ch5_PathNodes2.udk should work fine.
    Run towards the block in the center of the map, hit the X key on your keyboard,
    and watch as you have a flashlight that can now toggle on and off!


It may be wise to delete your UDKInput.ini file before rebuilding,
otherwise the engine may not use your changes. This way, during the next
rebuild, it will grab your update file and use that as the default settings.

How it works...


UDK provides a plethora of classes that we can subclass from. As SpotLightMovable suits
our needs well, we've just extended from that and only adjusted a few minor default properties
for our flashlight.


Afterwards, we attached the light to our pawn, then slightly offset the starting point of the
cone to begin from our pawn's eyes, before finally telling it to follow our controller's rotation,
so that it always faces the same direction our pawn is looking at.


Finally, we set a new input command in our DefaultInput.ini file, and bound our X key
to execute the function ToggleFlashlight.


Creating an explosive barrel


Guns aren't the only weapons we can make use of in UDK. It's time to think outside the box
for a bit and come up with some other creative weapons. For this next recipe, we'll create a
weapon that makes use of our environment, an explosive barrel.


Since the early days of gaming, the explosive barrel has been a primary tool in every level
designer's tool belt. Granted, I've never seen an explosive barrel in my life, but games would
lead you to believe otherwise.


With that in mind, let's create our barrel.

Free download pdf