Game Development Reference
In-Depth Information
Creating a gun that fires homing missiles
UDK already has a homing rocket launcher packaged with the dev kit ( UTWeap_
RocketLauncher ). The problem however, is that it isn't documented well; it has
a ton of excess code only necessary for multiplayer games played over a network,
and can only lock on when you have loaded three rockets.
We're going to change all of that, and allow our homing weapon to lock onto a pawn and fire
any projectile of our choice. We also need to change a few functions, so that our weapon fires
from the correct location and uses the pawn's rotation and not the camera's. These are the
same functions which we added to our ShockRifle class in Chapter 3 , Scripting a Camera
System . We'll need to create two classes for this first, so let's get started!
Getting ready
As I mentioned earlier, our main weapon for this chapter will extend from the UTWeap_
ShockRifle , as that gun offers a ton of great base functionality which we can build from.
Let's start by opening your IDE and creating a new weapon called MyWeapon , and have it
extend from UTWeap_ShockRifle as shown as follows:
class MyWeapon extends UTWeap_ShockRifle;
How to do it...
We need to start by adding all of the variables that we'll be needing for our lock on feature.
There are quite a few here, but they're all commented in pretty great detail. Much of this code
is straight from UDK's rocket launcher, that is why it looks familiar. In this recipe, we'll be
creating a base weapon which extends from one of the Unreal Tournament's most commonly
used weapons, the shock rifle, and base all of our weapons from that.
I've gone ahead and removed an unnecessary information, added comments, and
altered functionality so that we can lock onto pawns with any weapon, and fire only
one missile while doing so.
* Weapon lock on support
/** Class of the rocket to use when seeking */
var class<UTProjectile> SeekingRocketClass;
/** The frequency with which we will check for a lock */
var(Locking) float LockCheckTime;
Search Nedrilad ::

Custom Search