Traffic and Pedestrian AI
I'm new to gamedev.net just to let you know. I am 16 with great knowledge in VBasic, and adequate in C/C++. I also have good knowledge in 3ds max. I started to learn programming and 2d/3d design at 13. I'm working on a driving game that contains computer vehicles and pedestrians. It's been a 3-month project. So far I made the small level and a character that moves. I also made pedestrians but they're walking all over (Sidewalks, roads, fields, and even off the map), and they only go forward. I want to know how can I make computer vehicles follow lane directions and pedestrians stay on sidewalks. I also want to know how to make cars choose if they want to choose to turn left, right, or continue to go straight. If I haven't made myself clear on anything, please ask so I can clearify it. (Edit: Subject used to be "Vehicle and Pedestrian AI". "Traffic and Pedestrain AI" seems more of a better subject for this topic.) [Edited by - 3dagreez on February 1, 2005 9:49:12 PM]
Well, simulating a city is quite tricky! But there are a few things you can do.
One solution is to model your road network by a graph, where each intersection is one node. Your car is following the graph, and when arriving at a node, it can randomly choose one direction (or you can use a pathfinding algorithm to make your car go from one precise node to another).
By keeping the position of each node, you can know what is the direction the car should take from one node to arrive at the next one.
For pedestrians, you can choose the same principle, but their walk will look terribly straight. To make it a bit more realistic, you can add some randomness to their trajectory from one node to another, so that they will not follow a straight line, but go around. Also, you can make them choose another node when arriving "close" to their current goal, and not exactly on it. This way, they would not all change direction at the same spot.
Hope it helps!
One solution is to model your road network by a graph, where each intersection is one node. Your car is following the graph, and when arriving at a node, it can randomly choose one direction (or you can use a pathfinding algorithm to make your car go from one precise node to another).
By keeping the position of each node, you can know what is the direction the car should take from one node to arrive at the next one.
For pedestrians, you can choose the same principle, but their walk will look terribly straight. To make it a bit more realistic, you can add some randomness to their trajectory from one node to another, so that they will not follow a straight line, but go around. Also, you can make them choose another node when arriving "close" to their current goal, and not exactly on it. This way, they would not all change direction at the same spot.
Hope it helps!
It has been a real frustration.
I really don't know what you mean by a graph. I know what you're saying about making nodes. I've made dummies before that made cars go to another dummy. I've went around and wrote down the coordinates and made dummies. It did get very frustrating though, because I needed to know the next nodes.
I know the phrase "Keep It Small and Simple"; but I do have 'curvy' roads, ands when you have two nodes, the cars just cut the corners instead of gradually turning. I've tried having many dummies to gradually turn the car, but it doesn't seem like the programmer's way. Not to mention, when I have a car turn - say 90 degrees, it just turns *snap* 90 degrees, and continues going to the next node.
For the pedestrians - I have it where they can spawn if near them and disappearing if not in area (Has been a memory crisis before). But I just don't know what to use to keep pedestrians on sidewalks. Like what object should I use, and what properties should it contain.
I really don't know what you mean by a graph. I know what you're saying about making nodes. I've made dummies before that made cars go to another dummy. I've went around and wrote down the coordinates and made dummies. It did get very frustrating though, because I needed to know the next nodes.
I know the phrase "Keep It Small and Simple"; but I do have 'curvy' roads, ands when you have two nodes, the cars just cut the corners instead of gradually turning. I've tried having many dummies to gradually turn the car, but it doesn't seem like the programmer's way. Not to mention, when I have a car turn - say 90 degrees, it just turns *snap* 90 degrees, and continues going to the next node.
For the pedestrians - I have it where they can spawn if near them and disappearing if not in area (Has been a memory crisis before). But I just don't know what to use to keep pedestrians on sidewalks. Like what object should I use, and what properties should it contain.
Another thing I'd like to do is to have cars know traffic lights and right-a-ways.
here you go
http://www.gamasutra.com/features/20010124/adzima_01.htm
http://www.gamasutra.com/features/20010124/adzima_01.htm
My Website: ai-junkie.com | My Books: 'Programming Game AI by Example' & 'AI Techniques for Game Programming'
also look at flocking behaviours...
http://www.red3d.com/cwr/steer/
in particular path and crowd following.
http://www.red3d.com/cwr/steer/
in particular path and crowd following.
For all.
For each node, stamp it with the time when it was last processed (it was near a pedestrian/car/train/Bus/ect.)
You also give it a value.
That value gets bumped everytime someone walked near it, and slowly decays (exponentials would be nice for this).
You then add (in the temporaries) a calue representing penalties. (for eg. if someones there, you penelty it, if its on the road, penelty it unless the sign says walk, stuff like that).
Now, what you then do, is you scale each into sections of a division.
So, you find the sum of all the nodes in all forward directions (up to about 60 degrees from where it is facing should be ok, but it would have to see the intersections for traffic lights and the like).
You then scale them from 0...1
So that they inverse there proportians.
You then generate a random number from 0 to 1.
You pick the one it lands oon, and move to the node.
Traffic lights would change based on the amount of vehicles and/or people near them (simple logic).
This should work (with a very low processor requirement) as long as someone isn't watching a single pedestrian of car very closely. (as you would have cars basically going nowhere, just going around the block, or around a few blocks).
What basically happens, is that they spread out all over your map, but very slowly and randomly, so they will eventually spread out over the road (weight each with a nice little value, which will make the cars like being inside the city verry much).
you can also add "special effects" which happen either randomly or when some preset condition is met.
Some of these effects would be:
3 point turns
5 point turns
U turns
Cars breaking down
Car crashes
Police chases
Cars running red lights,
Ect.
Now, these will give your city traffic jams, and all sorts of nice things.
It will also make it almost interesting enough to watch for a few hours.
From,
Nice coder
[Edited by - Nice Coder on February 3, 2005 2:18:48 AM]
For each node, stamp it with the time when it was last processed (it was near a pedestrian/car/train/Bus/ect.)
You also give it a value.
That value gets bumped everytime someone walked near it, and slowly decays (exponentials would be nice for this).
You then add (in the temporaries) a calue representing penalties. (for eg. if someones there, you penelty it, if its on the road, penelty it unless the sign says walk, stuff like that).
Now, what you then do, is you scale each into sections of a division.
So, you find the sum of all the nodes in all forward directions (up to about 60 degrees from where it is facing should be ok, but it would have to see the intersections for traffic lights and the like).
You then scale them from 0...1
So that they inverse there proportians.
You then generate a random number from 0 to 1.
You pick the one it lands oon, and move to the node.
Traffic lights would change based on the amount of vehicles and/or people near them (simple logic).
This should work (with a very low processor requirement) as long as someone isn't watching a single pedestrian of car very closely. (as you would have cars basically going nowhere, just going around the block, or around a few blocks).
What basically happens, is that they spread out all over your map, but very slowly and randomly, so they will eventually spread out over the road (weight each with a nice little value, which will make the cars like being inside the city verry much).
you can also add "special effects" which happen either randomly or when some preset condition is met.
Some of these effects would be:
3 point turns
5 point turns
U turns
Cars breaking down
Car crashes
Police chases
Cars running red lights,
Ect.
Now, these will give your city traffic jams, and all sorts of nice things.
It will also make it almost interesting enough to watch for a few hours.
From,
Nice coder
[Edited by - Nice Coder on February 3, 2005 2:18:48 AM]
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement