Game Development Reference
Adding a flashlight to a weapon
Flashlights have been man's best friend to combat darkness since the invention of electricity.
A flashlight can even be turned into a weapon, as we saw with 2010's release of Remedy's
Alan Wake .
In the following recipe, we'll be creating a flashlight that can attach to the pawn, as well as a
weapon, and be toggled on and off with any key of your choice.
Start by creating a new class called WeaponFlashlight and have it extend from
SpotLightMovable . Also make it non placeable. Non placeable means that it cannot be
dropped onto the map. Essentially it's there to keep things clean for the level designers, and
avoid confusion as to how something should or should not be used.
For this recipe, we'll have to make small modifications to our TutoialPawn class, in addition
to creating one new class, which is our actual flashlight.
class WeaponFlashlight extends SpotLightMovable
How to do it...
SpotlightMoveable already has all of the functionality that we'll need, so we're
only going to adjust a few of the default properties.
Begin Object Name=SpotLightComponent0
// Sets the light color
// Cannot be deleted during play.
We decrease the RGB value of the light down from a full 255 to 200 so that we don't
have a blinding white light. I prefer a softer white with a subtle shadow. The inner and
outer cone angles will also greatly affect how the light is displayed on screen. Play
with the values for a bit to really get a feel for what works best for your needs.
The only things left to do from here are additions and alterations to our