Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am implementing car movement game (sort-of like Locomotion). So 60 times a second I have to advance the movement of each car. The problem is I have to look ahead to see if there is a slower car, stop sign, or red light ahead. And then slow down appropiately.

I also want to have the cars take time to go from stopped to full speed and again to slow down. I'm not implementing full-blown physics, but just a tick by tick speed up/slow down as that provides most of the realism to match what people expect to see.

The best I've come up with is to walk out the full distance the car would travel of it was slowing to a stop and see if anywhere along that path it needed to slow down or stop. And then move it forward appropiately.

I am moving the cars 60 times a second so I need this to be fast. And walking out that whole path each tick strikes me as processor intensive.

What's the best way to do this?

share|improve this question
Is this the same question? gamedev.stackexchange.com/questions/7963/… –  Anko Dec 8 '12 at 1:14
Not really. A lot of that is path finding which I've got covered. As to the mechanics of moving down the road, it discusses the same issues but just talks about the ways to avoid collisions, but not the mechanics of moving down the path step by step. –  David Thielen Dec 8 '12 at 4:24
add comment

1 Answer

First of all I would look into making computational intensive chunks less frequent. 60 updates per second sounds like way too many.

See if you can employ future planning - checking every obstacle returns for how many ticks it will be safe to ignore. E.g. when car checks its path ahead redlight "says" it wont switch for 240 ticks and slower car "says" it will not brake in next 157 ticks. So u safe to skip next equivalent of 157 ticks with regard to cars acceleration and etc - e.g. 124 ticks.

Another idea is to make it event-driven, so redlight would notify all cars in radius that they are required to stop. Same with traffic cars.

P.S. You did not mentioned how complex is your maps topology. Is it like freeways or tight streets with many intersections.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.