The code below is very similar to that of any pickup in UDK. I start by extending from UTAmmoPickupFactory, which gives the base characteristics we’ll be using. Although the class I’ve created is annoted pretty well within the class itself, I’ll explain in further detail. We’ll begin by describing the default properties.The default properties is for the most part the part of the code that defines the most common things we need.
//TELLS YOU HOW MUCH AMMO IT WILL DELIVER.
//TELLS YOU WHICH WEAPON IT IS ADDING AMMO FOR.
//MAKES THE PICKUP ROTATE!
//YOU GUESSED IT – HOW LONG (IN SEC) UNTIL AMMO RESPAWNS)
//EFFECTS HOW THE PICKUP BOBS UP AND DOWN
By swapping out the TargetWeapon=class with another class, you can tell the pickup which weapon it is providing ammunition for. The MaxDesireability value tells the AI how important an item is, and whether or not it will take preference for going after this item more than any other. For example, if we have a health pack with a value of .7 and an ammo refill with a value of .3, the AI will naturally head towards the health.
The BobSpeed and BobOffset adjust how quickly and how high the item floats up and down. If you choose to instead have a static item, simply remove these properties, or set them both as zero.
Begin Object Name=CollisionCylinder
From here, we start to develop the different components of the Pickup Factory. Components are just that: parts which make up this class. They can be anything from collision cylinders, to static meshes, particle effects and lighting. You will want to make the collision cylinder slight larger than the mesh itself, especially if you plan on creating a title which relies heavily on vehicles, such as DeathSentence. We need to begin each component of our factory with “Begin Object” and finish each one with “End Object”, otherwise the class doesn’t know where the properties one component ends and the next begins. From here we define the default properties of our object.
Next up is the Light Environment. This defines how well the light reflects off of the static meshes which make up the script. Without this, you’ll notice that your static meshes appear very dark, probably black. The RBGA values listed above are all floating point numbers (as referenced by the f following each one) and refer to red, blue, green, and alpha (transparent) channels naturally. The actual mesh for the ammo is up next. This is the item which will be floating above the base, and is what disappears when you pick up your ammo.
Begin Object Name=PickupLightEnvironment
The AmmoMeshComp is the next piece we’re working with, and this is the static mesh for the actual ammo we will be retrieving. Anytime your vehicle is in short supply and crosses the collision path, it will acquire the ammo and make it disappear until your determined respawn time. Again, the default properties here are the key traits which affect the meshs’ behavior and appearance. The translation uses the X,Y,Z axis to adjust how high or low it floats above the base mesh. The Scale adjusts the size of the mesh within the game, while the MaxDrawDistance dictates when the mesh will disappear from view. The higher the DrawDistance, the longer it stays in view, but at the cost of more system resources. Finally, the ‘Pickups.Ammo_Rockets.Mesh.S_Ammo_RocketLauncher’directs the script to look for this mesh. By simple swapping it out for another mesh you can change the appearance from something like the rocket, to bullets, or fuel cells.
Begin Object Name=AmmoMeshComp
The PickupBaseMeshComp is equally important, as it is lower most piece of our puzzle. It serves as the base from which our ammunition will float. The properties are similar to those found in the AmmoMesh, however now you’ll see that I’ve lowered the Z value to -10 so that it rests lower than the floating ammo.
//THIS IS THE BASE, BENEATH THE AMMO
Begin Object Name=PickupBaseMeshComp