Advertisement

Obstacle avoidance in gta style game

Started by March 25, 2010 10:28 PM
3 comments, last by snake5 14 years, 7 months ago
Hello, Currently I am developing a gta style free roam game. My traffic cars roam in the city using waypoint navigation. However I want to find if I place my own car between the path of the traffic cars how can they avoid the obstacle by turning left or right and then continuing to their original path??? And if the car reach too close to my car then they take back to certain distance and then turn left or right to continue to their original path.
You are probably going to want to make a "navmesh" aka a navigation mesh which is a mesh that describes where it is ok for cars to go and where it isnt.

Then, you are going to want to use something like an A* algorithm on the navmesh to let the cars path find around obstacles.

After you have that working, making the cars act realistically (ie doing 3 point turns when appropriate etc) might take some work (;

Also not sure if it helps but a nice alternate way of laying down paths for traffic cars other than way point navigations is to lay down SPLINES (aka bezier curves and such).

That lets cars follow smooth curved paths which can look a lot nicer than way points.
Advertisement
Oh and something else nice is when you make your navmesh, you can assign a "type" to each part.

Like for instance you can mark a peice as street, another as crosswalk, another as grass, another as sidewalk etc.

Doing this you can assign different costs (weights) to each material type, so that cars will REALLY prefer to drive on the road if they can, but if all else fails they will drive up on the sidewalk.

Also with a setup like this, you can have the people in your city use the navmesh for navigation as well, and make sure that they prefer to walk on sidewalk, but will also walk on crosswalks, and perhaps grass if they need to.

It's multipurpose :P
A navigation mesh would indeed be the common way to solve this. However, you can give a width to each waypoint and a width to the connections between them. This means you get a 2D oriented rectangle as a description of the road, which should allow you to do your intersection tests to see if there's any room left to squeeze past or not...

If you have waypoints already, this approach might be the quickest.

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!

Quote: how can they avoid the obstacle by turning left or right and then continuing to their original path???

Good news for you: you don't have to calculate the path for cars instantly. They can stop.. More good news: Cars can also have waypoint nodes attached so you could as well put 8 nodes around the car in way and connect the closest ones and then - let your car go that way. :)
For a GTA style game, you can just make that car more powerful and at least try to check if something intersects the lines between 2-4 next viewports and adjust the path.

This topic is closed to new replies.

Advertisement