- Home /
Cars in City
I am trying to figure out how to accomplish this: AI cars driving around in the city. I figured I can have the AI cars behave as if they are on a race track. I have found this script here. If I were to do this, I would have to have AI cars in the right lane, and AI cars in the left lane at all times, they wouldn't be able to make a u-turn, or switch lanes, etc.
So my main question(s) are: whats the best approach to have AI cars stop at a stop light? If I make the AI cars able to collide with my car (which I can drive freely), will the AI cars be able to continue driving after I hit them?
Are there any examples out there that do what I am looking for?
Thanks in advance
Answer by DaveA · Jul 14, 2011 at 05:22 PM
I would look into the A* script on the script wiki. Basically you set up waypoints that the cars would follow. You could set up proximity detection (via colliders and isTrigger) for stop lights to inform the car that it is near one, then see if it's facing the light, and if the light is red, tell it to stop.
It's up to you how you want them to behave on collision. You could inflict damage (or not) and have them still drive (or not) (or 'badly') When the damage adds up to 'bad enough' then they would just stop executing the 'drive' behavior (based on A*)
Your answer
![](https://koobas.hobune.stream/wayback/20220612143440im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Steering an AI vehicle to a waypoint using float of -1 to 1? 1 Answer
Car- can someone help me convert this to C#? 1 Answer
How to make waypoints 8 Answers
Check whether car has passed a point in world space 1 Answer
How To Add AI To Car/Racer? 4 Answers