![]() |
Night Vision Goggles - author: [mr.self-destruct] | |||
This tutorial outlines one means of achieving a night vision goggles effect, the code is complete, but you must create the necessary
textures yourself.
Night vision goggles can be broken down into two parts, the first is providing better illumination and the second is flashy graphics.
The essential part is devising a means of illuminating objects & scenery for one player's view only (thus most likely a client side only
effect). The approach I've taken is to use two techniques for this. The first is to adjust the player's view glow to brighten their view
(and colour it as part of the flashy effects). The second is to create an effect that encompasses other players making them more visible.
To be able to draw onto the player's view, I've used a HUD mutator, which allows us to hook into PostRender() and draw our animated texture.
This approach is used by the UT relics, so the relic code can be used as a basis to work from.
var PlayerPawn PlayerOwner;
// If the mutator hasn't been registered, register it
// RegisterHUDMutator that keeps track of the HUD's owner
ForEach AllActors(class'PlayerPawn', P)
// If the player has NVG, draw overlay
if ( PlayerOwner == None )
if ( NextHUDMutator != None )
defaultproperties
Next comes the actual NVG inventory object, this ties everything together. It's job is to ensure that the player using it has the necessary HUD
mutator in play and to implement the remaining functionality for the night vision goggles. It also provides an exec function for turning the
night vision goggles on or off.
var float Range; // Illumination range of NVG
replication
// Toggle NVG
// Ensure that NVG effects are disabled when NVG is destroyed or dropped
function Destroyed()
Super.Destroyed();
function DropFrom(vector StartLocation)
bEnabled = false;
// Adjust view glow; brighter when NVG activated
PP = PlayerPawn(Owner);
// Ensure that the player has an NVGMutator
if ( Level.NetMode == NM_DedicatedServer )
CheckForHUDMutator();
// Check for an NVGMutator, spawn one if necessary
if ( Role == ROLE_SimulatedProxy )
// Ensure that the player has an NVGMutator
// Spawn and locate NVGIllum objects
simulated function Tick(float DeltaTime)
if (Owner == None)
// Client side only
// Only update every third tick to reduce CPU usage
// Count number of NVGIllum objects on client
defaultproperties
Finally we come to the aura effect:
var int FatnessOffset;
simulated function Destroyed()
simulated function Tick(float DeltaTime)
if ( bHidden || (Level.NetMode == NM_DedicatedServer) || (Owner == None) )
IdealFatness = Owner.Fatness; // Convert to int for safety.
if ( Fatness > IdealFatness )
defaultproperties
And now you should have working night vision goggles. The code could undoubtably be improved, mostly to reduce the performance hit (which is
around 15fps on my PC); all those iterators in Tick() are not a good thing.
|
|||
suggestions? questions? comments? please send them all to ray@beyondunreal.com |
copyright
2001 ray davis. this site and all content belongs to me unless
otherwise noted, with the exception of some tutorials. the authors
retain the rights to their material, and are hosted here with their
express permission. everything else is mine though, so don't steal
it. bastards. privacy |