Skip to content
Menu
Mob City
  • Home
  • Contact
  • About
Mob City

Traffic system and cars

Posted on March 2, 2025

Earlier I posted about A Star path finding algorithm for car traffic. In this post, I’ll show how we use it.

First, I rendered all 8 directions in Blender for two types of roads – main roads and normal roads – and manually placed them to see how they looked together. After some back-and-forth between Blender for rendering and Krita for a bit of post-render polish, I think the result turned out pretty nice.

Next, I needed to mark the relative tile coordinates within each road sprite. But more importantly, I had to connect them to form makeshift waypoints for pathfinding. You can see a partial code snippet below showing how that setup works.

The idea is to place a tile by supplying its own coordinates along with the coordinates of the next tile it connects to. It only connects one way, which is useful for representing one-way lanes in the traffic system.

Here’s how it looks when overlaying a debug tile I made to visualize the network. (Note: the normal T-junction isn’t connected yet in this image.)

Connecting all 16+ different road tiles by marking their entry and exit nodes was a bit laborious, but thankfully, it’s a one-time job.

Once that was done, I brought in some car assets I found online. There are two normal-speed cars (a Chevy and a Falconer), one fast car (Cord), a police car, and a truck. I also added some boxes to the truck to visually indicate it’s loaded with goods ready for transport.

The final step was to place the vehicles on the map and hook them up to the traffic pathfinding algorithm to make sure they follow the correct routes.

It blended nicely with the road, helping maintain the aesthetic cohesiveness and overall immersion of the environment. I was pretty happy with how it all came together.

And here’s the final result: a police car following the traffic lanes using the pathfinding system.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Modular building graphics
  • Lit up mode in night time
  • Night mode (tinting with shaders)
  • Traffic system and cars
  • Animation
©2025 Mob City