Game Development Reference
Load up your map with a few bots on it, hold your aiming reticule over it for a brief moment
and when you hear the lock sound, fire away!
How it works...
To keep things simple we extend from UTWeap_ShockRifle . This gave us a great bit of base
functionality to work from. We created a MyWeapon class which offers not only everything that
the shock rifle does, but also the ability to lock onto targets.
When we aim our target reticule over an enemy bot, it checks for a number of things. First,
it verifies that it is an enemy and also whether or not the target can be reached. It does this
by drawing a trace and returns any actors which may fall in our weapon's path. If all of these
things check out, then it begins to lock onto our target after we've held the reticule over the
enemy for a set period of time. We then fire our projectile, which is either the weapon's firing
mode, or in our case, a rocket.
We didn't want to clutter the defaultproperties block for MyWeapon ; so we create a
child class called MyWeapon_HomingRocket that makes use of all the functionality and
only changes the defaultproperties block, which will influence the weapon's aesthetics,
sound effects, and even some functionality with the target lock.
Creating a gun that heals pawns
UDK has built-in functionality for healing players through pickups such as health packs,
but there is no way for one player to heal another.
In the following recipe, we'll create an instant hit weapon that heals a target for 10 points
of health each time it is shot.
Start by creating a new class called MyWeapon_HealingInstantHit and have it extend
from MyWeapon .
class MyWeapon_HealingInstantHit extends MyWeapon;
How to do it...
The great thing about setting up our MyWeapon class is that adding additional
functionality to it is a breeze. This class has only one function. Let's add the
ProcessInstantHit() function now.