Making a traffic simulation/system?

Hello,

I know how to make an object move forward, that’s simple. But, how would I make a traffic car simulation/system?

Hehe…the difference between moving an object forward and implementing a traffic simulation is kind of like the difference between nailing two boards together and building and house :slight_smile:

What will be involved does depend though on what features you need and how complex you want the simulation to be. For example, at its simplest, such a system could just consist of preset animations or motion paths that repeat in a cycle.

A more or less realistic traffic simulator will be pretty complex though (such software exists and is used by civil engineers and so forth). Such a system might employ fuzzy logic and other methods to realistically simulate human driving behavior and the traffic patterns that result.

Realistically though, you’d probably want to go for the simplest solution that would be appropriate for the context. To offer more specific advice though, we’d probably need to know more about the requirements.

I suppose if I could code at all. I’d probably start by making an intelligent Car A.I. create some kind of road system that it could see, randomize various things like would it or wouldn’t it overtake another car, would it be going to a specific location or simply traveling around aimlessly (for giving the impression of reality with lots of those around). You could probably even have them use a built in timetable, less cars moving around at night, more around 8:30am, so on and so forth.

Then set them up to recognize and respond correctly to traffic lights. After that come up with the traffic light system itself. Which will be where you realize why traffic planners are paid so much, lol. Once you’ve got that system in place though, the individual car A.I. will behave correctly… hopefully…

But yeah, as Jesse said, it’s bloody complicated and something like that would challenge very talented programmers.

What I want them to do is travel on a road(most likely w/waypoints), stop, and go at traffic lights. I have a traffic light code shown here:

var Red : Light;
var Green : Light;
var Yellow : Light;

function Start()
{

Yellow.enabled = false;

while(true)
{
Green.enabled = true;
Red.enabled = false;
yield WaitForSeconds(30);
Yellow.enabled = true;
Green.enabled = false;
yield WaitForSeconds(4);
Red.enabled = true;
Yellow.enabled = false;
yield WaitForSeconds (30);
}

}

Any more info you need to know?

Do the cars need to turn? Or for the sake of simplicity, can they always go straight when they hit a light? Obviously with no turns cars can’t ‘loop around’, but depending on the context, it might work to have vehicles simply ‘disappear’ when they get to the end of the level and teleport/respawn somewhere else.

@Frank: You’re really throwing me off with your constantly changing avatar! (At least things are less confusing now - for a while there, there were about 5 people using the ‘Unity cube’ :slight_smile:

They need to turn, but their wheels dont need to.

lol, the unity 64 avatars were beginning to confuse me too, I started missing replies thinking people were talking to other users :slight_smile:

For traffic, is it like an RTS where you have to see the cars or like GTA where you can get away with random movements?

Well, more like GTA. But, just not that advanced. Something like in this video:

Just cars that move and turn, and stop at stoplights. :slight_smile:

Midtown madness <3 old school Nice :smile:

Make cars drive along a predefined path?

Yes. But, they need to stop at traffic lights, etc. :slight_smile:

Place a trigger at the place of stops and then check if traffic is red or green?

That could possibly work. :slight_smile:

Update. I made a car that goes around in a circuit around waypoints. :slight_smile: How would I do that trigger thing? It needs to detect a trafficlight (the correct one), etc.

Would something like that be possible? That would seem to be a better solution to my problem. Ideas on how to do it if it’s possible? Btw, that’s from here. :slight_smile:

BUMP. Would that be possible?! :face_with_spiral_eyes: If so, How would I start something like that?

This is pretty easy to do with Unity. Just off the top of my head, I can think of a few ways to do it using empties that let the cars know what to do at certain intersections. ;o For random turns it’s a bit more planning.

But 2dfxman had a pretty good suggestion. The least work possible is to use predefined paths.

Yes. But this is a city. Not just one straight road. :wink: I need a way for any car to follow the roads. Can you please tell me those few ways that you can think of? I’ll see if I can try one. :slight_smile:

Well my way doesn’t mean a straight line.

Update. I made a car that goes around in a circuit around waypoints.

This is actually what I was thinking. If you have waypoints then you can model a system that looks like traffic…even if it is not random.