AI Traffic and Obstacle Avoidance

Screenshots.PNG

Traffic Chaos (I mean Control)

The traffic system in Pigeon Simulator had a number of requirements for this first pass. The cars driving needed to be physics based. Meaning the cars need to functionally work very similar to how cars drive in the real world, and also be able to be knocked off the road and get back. The cars also needed to be able to avoid obstacles. So if in a weird happenstance a building were to fall onto the road the cars would be able to see the new obstacle and stop to avoid hitting it. And finally, the most important requirement is that the cars need to be able to drive their paths without ramming into each other and exploding. They need to be able to exist on their own with no interference and be stable. That last one is something that I may be working on for a long time. But for now join me on the journey to get these cars moving and grooving down the streets!

 

This is the basics of the car movement. Cars follow along roads and when they reach an intersection they can transition along a curve to reach the next road’s right lane. This is a simple example, mainly because none of the cars have any collision or obstacle avoidance on them. But all things start from basic roots so we start from here!

 

Upgrades!

Now here’s some progress. And new challenges. We added intersections and a basic timed light system, and added an obstacle avoidance system. Essentially if a car sees an obstacle in-front of it, it will do it’s best to slow down and stop. Put this through every car in the city and they can stop and wait for each other at lights!

The avoidance system had to be a little more advanced to make sure cars didn’t pickup the wrong things as obstacles. The blue rectangles in-front of the cars show the viewing box that the cars can see. Any obstacle that gets into that blue will then trigger the cars to slow down and the box will change to red.

Debug boxes showing vision cubes of the cars

CollisionDetectionArea.PNG
This red box is a near dynamic vision box and can shrink in size, the longer the car is detecting an obstacles

This red box is a near dynamic vision box and can shrink in size, the longer the car is detecting an obstacles

One issue that cropped up was that cars turning into a road can detect cars in the opposite lane as obstacles. And in doing so stopping in the middle of an intersection and causing all sorts of disasters. The solution was to make the car’s view distance and acceleration variable. Meaning that when a car is slowed down it can see less far ahead an accelerates slower. This solved the issues of cars gunning it out of intersections as well as them turning into congested lanes.

 

Bugs Bugs Bugs

Now I could say that all this went easy peasy no bugs or problems but where is the fun in that. So in the spirit of open development here are some of the best bugs recorded.

Turning the acceleration down a little to much. We call it the Tokyo Drift.

The Roll-Through

I honestly don’t know how I did this. But it’s called the WEEEEEEEE!!

 

Final Result (So Far…)

This is where the cars stand currently. We swapped up the intersections to me more intelligent by using a registering and de-registering structure and this allowed us to have much more cars moving through the city. We also added with a despawning and respawning system and it’s not too shabby. There are definitely still improvements to be made. Smarter respawning and better collision detection are on the list for sure but this is good stepping stone for some solid procedural chaos in in Pigeon Simulator!

Sidenote: We did some optimizations as well. Like precomputing all the possible paths along an intersection. Which make an awesome looking star thingy seen below!

Precomputing.png