What's the best way to move cars along roads
- by David Thielen
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?