Game Development Community

Trying to get fxLight to flicker

by Andy Hawkins · in Torque Game Engine · 04/20/2007 (8:27 am) · 4 replies

I want to add fxLights to the scene and make them flicker for fire and torchlight. I wrote this function thinking if I randomised the colour time to lerp between the min and max colours and then call itself again after that time to do it all over, I would get randomly flicking light. Unfortunately, while it does call the function at the random time specified, the colourTime for the light remains the same. Is it possible to do?

// light datablocks
datablock fxLightData(yellowLight)
{
  FlareOn = true;
  FlareBitmap =  "common/lighting/corona";
  LightRadius = 5;
  RadiusTime = 5;
  AnimBrightness = true;
  AnimRadius = true;
  MinBrightness = "0.8";
  MaxBrightness = "1.0";
  RadiusTime = "1.0";
  BrightnessTime = "1.0";
  BrightnessKeys = "AZM";
  Colour = "0.75 0.65 0.4";
  MinRadius = "2.7";
  MaxRadius = "3.0";
};

function Light_InitTorchLight(%name, %nameTag)
{
   //search for a light of type name and change its colour sequence time
   %position = "0 0 0";
   %radius = 100000.0;
   InitContainerRadiusSearch(%position, %radius, $TypeMasks::StaticTSObjectType);
   
   while ((%targetObject = containerSearchNext()) != 0)
   {
      if (%targetobject.getDataBlock().getName() $= %name)
      {
         if (%targetObject.nameTag $= %nameTag)
         {
            // set random light time
            %obj = %targetobject.getDataBlock();
            changeLightTime(%obj);            
         }
      }
   }
}

function changeLightTime(%obj)
{
   cancel($torchLightSchedule);
   
   // set random light time
   %lightTime = getRandom(50,70);
   %obj.BrightnessTime = %lightTime;
   %obj.RadiusTime = %lightTime;
   
   $torchLightSchedule = schedule( %lightTime, 0,  changeLightTime, %this, %obj);
}

#1
04/20/2007 (8:30 am)
Meh... seems to work now. SO!!! Here's how you make a flickering light...eh heh...hmmm
#2
04/20/2007 (9:59 am)
Thanks for posting a question with the follow-up answer for us Andy =). Works well.
#3
04/20/2007 (10:16 am)
NP :) You can change the Light_InitTorchLight function to something else. I just search for lights added to the scene from the mission editor file, called %name - that's their datablock name, and %nameTag to narrow the light types to what you want to light. So you would only make lights of %nameTag = "flickerMe" of type "yellowLight" if you want, and it still allows you to use the default "yellowLight" for other lights that don't flicker.
#4
04/20/2007 (11:47 am)
One way I did this is to link a TLK light to a particle emitter. Makes for a really nice flickering effect, although I'm not sure if it requires more CPU effort to do so.