Game Development Community

Traffic lights

by Travis Vroman · in Torque Game Engine · 06/12/2004 (6:58 pm) · 19 replies

I was wondering if there is a way to set up traffic lights on a timed system so the lights change at regular intervals. For example, stays red for 15 seconds, goes yellow for 3 seconds, stays green for another fifteen seconds, then starts over. I know the fxLight should be used for this, due to its versatility during gameplay. Any ideas? Melv maybe you can help me? Thanks as always,

-Barzahd

#1
06/12/2004 (7:02 pm)
There is a few ways I can think of, theres a resource that uses the alpha layer to use a light, you could use that and TSe's texture animation technolodgy if wanted. Or you could set up a system like the 1 2 3 system in the starter.racing, where it coulds and changed teh texture of the diff or dts.
#2
06/12/2004 (7:08 pm)
Http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4962



I believe
#3
06/12/2004 (7:16 pm)
Chris, I did look into that, but in my situation that won't work. You see, I need the flares from the fxLight to change, so later on I can tie that to the paths for the traffic I have set up. Right now all the cars follow thier paths, but dont stop at intersections, so they always hit each other. What I'm looking to do is find a way to tell the vehicles to stop when the signal turns red, meaning I need more than an animation. So, I thought if I could set up a timer sort of like an on/off switch for the fxLight, I could also tie that timer to the traffic.
#4
06/12/2004 (8:19 pm)
Schedule the change with %obj.schedule()? Thats what I would do... Seems to be the only way really. Dont know how you could make that work with fxLights, but you could easily tie it up to a trigger so that cars inside the trigger stop/slow and go at the appropriate time.
#5
06/12/2004 (8:35 pm)
Ok, souns like that would work, but I dont have the first clue where to implement these changes.
#6
06/12/2004 (10:30 pm)
Is it possible that this could be done using some sort of trigger?
#7
06/13/2004 (12:44 am)
You can have it react on a trigger, or you can use a schedule...

You can for example use a static shape, make a datablock for it, and have it start with the first schedule in its onAdd event. Then each schedule can call the next schedule, and each time you can change the texture of the model (your texture will have to be named base.texturename.png for this to work).
An extra could indeed be light, I would suggest having more then 1 datablock for the light and let the object change datablocks, would that work? haven't played around with this yet.
#8
06/17/2004 (6:48 pm)
Can this be done through a function possibly? for ex. could I make something called:

function TrafficLightRedData::onAdd(%this,%obj)

and then use %obj.schedule() to change weather or not the light is lit? (in this case the red light)
#9
06/17/2004 (7:24 pm)
Ok, here's what I've come up with, but it doesn't work. Keep in mind this is my first real attempt at anything like this, so I don't really know what I'm doing. But hey, at least I'm trying to figure this out. I've created a file called lights.cs and loaded it from game.cs (that part works fine). The light is created, but it doesn't disappear.

//=======================================
   datablock fxLightData(fxTraffLtRed)
   {
    //  category = "TrafficLight";
      LightOn = true;
      Radius = 1.0;
      Brightness = 1.0;
      Colour = "1 0 0";
   
      FlareOn = true;
      FlareTP = true;
      FlareBitmap = "common/lighting/corona";
      FlareColour = "1 0 0";
      ConstantSizeOn = false;
      ConstantSize = 1.0;
      NearSize = 3.0;
      FarSize = 0.5;
      NearDistance = 10.0;
      FarDistance = 30.0;
      FadeTime = 0.1;
      BlendMode = 0;
   
      AnimColour = false;
      AnimBrightness = false;
      AnimRadius = false;
      AnimOffset = true;
      AnimRotation = false;
      LinkFlare = true;
      LinkFlareSize = false;
      MinColour = "0 0 0";
      MaxColour = "1 0 0";
      MinBrightness = 0.0;
      MaxBrightness = 1.0;
      MinRadius = 0.1;
      MaxRadius = 20.0;
      StartOffset = "-5 0 0";
      EndOffset = "5 0 0";
      MinRotation = 0;
      MaxRotation = 350;
      SingleColourKeys = true;
      RedKeys = "AZA";
      GreenKeys = "AZA";
      BlueKeys = "AZA";
      BrightnessKeys = "AZA";
      RadiusKeys = "AZA";
      OffsetKeys = "AZA";
      RotationKeys = "AZA";
      ColourTime = 1.0;
      BrightnessTime = 1.0;
      RadiusTime = 5.0;
      OffsetTime = 5.0;
      RotationTime = 5.0;
      LerpColour = true;
      LerpBrightness = true;
      LerpRadius = true;
      LerpOffset = true;
      LerpRotation = true;
   };


//====================================
function fxTraffLtRed::create(%block)
{
   %obj = new fxLightData() {
      dataBlock = %block;
   };
   return(%obj);
}
//============================================
function fxTraffLtRed::onAdd(%this,%obj)
{
   %obj.schedule(3000, "LightOn = false");
}

Can anybody make any sense out of this or help me try to? Please any help is appreciated.

-Barzahd
#10
06/17/2004 (8:57 pm)
You'll need to add another function... either toggleLight or lightOn, lightOff.

function fxTraffLtRed::toggleLight(%this) {
  if(%this.LightOn == false) {
     %this.LightOn = true;
     echo("The light is on");
  }
  else { 
     %this.LightOn = false; 
     echo("The light is off");
  }

}


Then change your schedule to:
%obj.schedule(3000, %obj.toggleLight());
I think that will work.
#11
06/18/2004 (2:47 pm)
Okay something is still wrong somewhere. Here's what I have now:

datablock fxLightData(fxTraffLtRed)
{
 //  category = "TrafficLight";
   LightOn = true;
   Radius = 1.0;
   Brightness = 1.0;
   Colour = "1 0 0";
   
   FlareOn = true;
   FlareTP = true;
   FlareBitmap = "common/lighting/corona";
   FlareColour = "1 0 0";
   ConstantSizeOn = false;
   ConstantSize = 1.0;
   NearSize = 3.0;
   FarSize = 0.5;
   NearDistance = 10.0;
   FarDistance = 30.0;
   FadeTime = 0.1;
   BlendMode = 0;
   
   AnimColour = false;
   AnimBrightness = false;
   AnimRadius = false;
   AnimOffset = true;
   AnimRotation = false;
   LinkFlare = true;
   LinkFlareSize = false;
   MinColour = "0 0 0";
   MaxColour = "1 0 0";
   MinBrightness = 0.0;
   MaxBrightness = 1.0;
   MinRadius = 0.1;
   MaxRadius = 20.0;
   StartOffset = "-5 0 0";
   EndOffset = "5 0 0";
   MinRotation = 0;
   MaxRotation = 350;
   SingleColourKeys = true;
   RedKeys = "AZA";
   GreenKeys = "AZA";
   BlueKeys = "AZA";
   BrightnessKeys = "AZA";
   RadiusKeys = "AZA";
   OffsetKeys = "AZA";
   RotationKeys = "AZA";
   ColourTime = 1.0;
   BrightnessTime = 1.0;
   RadiusTime = 5.0;
   OffsetTime = 5.0;
   RotationTime = 5.0;
   LerpColour = true;
   LerpBrightness = true;
   LerpRadius = true;
   LerpOffset = true;
   LerpRotation = true;
};


//====================================
function fxTraffLtRed::create(%block)
{
   %obj = new fxLightData() {
      dataBlock = %block;
   };
   return(%obj);
}
//=============================================
function fxTraffLtRed::toggleLight(%this) {
  if(%this.LightOn = false) {
     %this.LightOn = true;
     echo("The light is on");
  }
  else {
      %this.LightOn = false;
      echo("The light is off");
  }
}

//============================================
function fxTraffLtRed::onAdd(%this,%obj)
{
   %obj.schedule(3000, %obj.toggleLight());
}

the light still does not go out like it should after it's created. What am I doing wrong?
#12
06/18/2004 (3:09 pm)
This line...
if(%this.LightOn = false) {

should be this:
if(%this.LightOn == false) {

A single equals symbol is assignment... meaning you're setting the lightOn to false... a double equals is comparison, meaning it checks to see if they are equal. Eveything else looks good at a glance.
#13
06/18/2004 (4:06 pm)
Ok fixed that but nothing happens even still
#14
06/19/2004 (12:19 pm)
I hate to keep buggin everyone, but I just can't seem to get this working no matter what I do. Can someone please help me?
#15
06/19/2004 (12:20 pm)
I'm starting to go beyond my real knowledge... but I'm not sure when the onAdd function is called. I'm not sure when the create function is called either. How are you adding this to your mission? I know that if you are running the mission editor and drop the object in, the onAdd function is called, but I don't know if there are other times it is called. Put echo functions everywhere, then check the console to see where it gets to and where it doesn't.
#16
06/19/2004 (12:55 pm)
I add it into my mission by going into the creator, going to environments and selecting fxLight, then selecting the datablock that I want to use.
#17
06/20/2004 (5:04 am)
I did something like this last year, I modified the lightFX to except mounting to mountPoints for easy attachment.

Heres the resource if you want it.. It includes the modified fxLight, a dts traffic light + texture, and support script..

Get it here
#18
04/23/2008 (1:22 am)
Does anyone have this working?

Thanks.
#19
04/23/2008 (10:55 am)
Holy mother of Bumps Batman !

lol sorry couldn't resist that :)

Also sorry I can't help... completely OffTopic.. I apologise.

:D