3
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\begingroup\$ Is this the same question? gamedev.stackexchange.com/questions/7963/… \$\endgroup\$
    – Anko
    Dec 8, 2012 at 1:14
  • \$\begingroup\$ 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. \$\endgroup\$ Dec 8, 2012 at 4:24

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Real-life systems like these usually use a form of fuzzy logic along with other control systems. Scan the surroundings to give the fuzzy logic system inputs regarding how close obstacles are, grade of turn, etc., as well as current speed, turning angle, and other vehicle state. Those inputs are used to calculate steering, breaking, gas, and so on. The obstacle detection can also take into account obstacles that aren't just in front of the vehicle but also around it, consider their relative velocities to the AI vehicle, accelerations, etc. The systems get complex but they're built off the same foundation.

Additional reading:

More game-y applications (racing games) still use similar approaches. Some are using neural networks and human players to teach the AI about how to respond rather than a manually-designed fuzzy system. Sometimes they even bake the neural net independently for each course letting the AI learn tricks specific to that course, e.g. when best to start turning to pull off a particularly tricky drift in a racing game.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .