Sign in to follow this  
BleuBleu

Update sequence in car simulation

Recommended Posts

BleuBleu    100
Hi!

I'm programming AI in a car driving simulator where a bunch of AI vehicles just drive around a city.

Each vehicle is updated one-by-one. When updating, each vehicle makes a few decisions (change lanes, change acceleration, etc.).

PROBLEM: To make its decisions, a vehicles studies its surroundings (look if there is enough room to change lane, check right-of-ways, etc.) but the surrounding vehicles might have been updated before in the frame, or might be updated later. So the current vehicle might be looking at old or new information.

In practice since time steps are relatively small, it works OK, but I want your opinion on how AI programmers usually deal with those issues.

I see 2 solutions:

1) Not do anything, should be good enough.

2) Separate update code in 2 steps. Vehicle::Update() and Vehicle::PostUpdate() where Update() makes the decisions and PostUpdate() actually modifies the vehicle position and other attributes. Would work, but annoying to program.

What do you guys think?

[Edited by - BleuBleu on November 13, 2010 11:03:31 PM]

Share this post


Link to post
Share on other sites
DekuTree64    1168
Yep, those are my usual two methods. First is fine in the vast majority of cases. Driving is a naturally delayed-reaction activity, with the human reaction time, and necessity of looking ahead and turning/accelerating/decelerating before anything happens anyway. Highly unlikely that even you would be able to spot the differences between the two update styles in this case.

Second style is mainly important in things like fighting games, where you don't want to give one player an advantage by updating first.

Share this post


Link to post
Share on other sites
Buckeye    10747
In an ideal world, drivers would indicate their intentions in some way - using signals for lane-changing, turning, brake lights, etc. In addition, "rules of the road" provide additional feedback - drivers are not responsible for cars behind them, yield to the right at intersections, etc.

You can divide your update into two steps, make decisions about lane-changing, turns, etc., and set "intention" signals for all cars. Then do a second update and, considering the intentions of cars involved, determine the action for each car. That's pretty much like your second method, but doesn't involve any actual actions in the first round, and shouldn't be that difficult to incorporate.

Racing games are a bit different in that there aren't any indications of intentions, only a general knowledge of what one driver should be able to expect from another driver (sort of knowing another driver's intentions). Not guessing correctly is what leads to actual collisions. However, you can add AI for guessing what another driver may do in particular situations.

Depends on how complicated you want to make it all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this