Resources Building a Traffic System

Godot Version

godot-4

Question

I am building an arcady car gameand I would like some resources on how to implement a working traffic system. The idea would be to recreate a small lively neighborhood : programming logic, scripts division, scene structures, etc. I am looking for inspiration and maybe advice on “best practices” and such.

1 Like

What’s a “traffic system”?

1 Like

A traffic system would be a system that manages multiple ai car entities that would have their own routes, behaviors, and react to surrounding environment (i.e. other cars, traffic light, follow traffic rules), etc.

Am I using the wrong term?

It depends a lot on your city and road logic. Is it grid based, or free curved roads. Is it 2D or 3D? How complex should the road system get, how many lanes per road? Do you plan traffic light logic?
Can cars take over other cars etc.
The base is some kind of path finding (like a*) if it is grid based. If it is “free”, than some logic with nodes at the crossings (and at start and target location), than some kind of tree logic to find a path in it (variant of path finding). Than some collision detection between the cars, or handled by road segments. That depends on how many cars can fit into a road segment, problematic with different sized cars (like trucks). It’s a rabbit hole.
EDIT:
And at some level of complexity, you have to calculate the simulation independent from the graphics, and render only the visible parts of it.

Why would you need a system that manages multiple cars? Are you being managed when you go somewhere in your car? You just need to follow the basic traffic rules.

Make a car that manages itself and just duplicate it.

It is 3D. Not sure what you mean by grid, I am using PathFollow on curves at the moment.
up to 4 lanes, traffic light logic, take over, everything just like a “real life” city.

for now, I am using a god like camera.

so a AI car script with everything in it, a script to spawn the cars, and that’ s it?

It could be important to avoid traffic jams.

well, that’s actually why I added behavior, I would like to have faster and slower cars so traffic jams would happen and cars would make choices based on it. The ideia is a it of chaos

Don’t systemize in advance. Start with a single car that can go anywhere on your roads. That said, modeling a road network may be a much more important problem to solve than a car. In any case, it would be a prerequisite so start with that.

1 Like

How many cars do you want to simulate?
With only a few, than you could use the jolt car physic, but if you want use 40+ cars, the car logic must be simplified. And just drive from node to node on your calculated path. Detect cars in front of you and react to them.
Not sure where your problem is, what do you want to know exactly.
Here some chaos with car physics and logic on every car. But I have reached some early limits with it.

AH yes, that’s it : it’s called a traffic simulation. Thanks
My problem was I couldn’t find any resources from which I could get inspiration.
Now using traffic simulation + godot in my SE I found a bunch of stuff!