Jump to content
  • Advertisement
Sign in to follow this  
_Flecko

Braking algorithms for AI

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my 2D game there are a number of vehicles that move in one or two dimensions, and I'm having trouble getting the AI to brake so that they'll stop at a desired position. Some vehicles, like the jeep, have an actual brake button (which is necessary because the slope of the terrain influences their velocity), others like the helicopter can be braked by accelerating in the opposite direction or just waiting for drag to slow them down. The controls are such that the player (AI or human) is either accelerating it in some direction at a constant, predetermined rate or not at all. For this reason, some estimation will probably need to be used, since there are a finite number of rates of acceleration the vehicle could have at a given time. So, my question is, what are some good ways for having the AI figure out what controls to press in order to stop at a given position.

Share this post


Link to post
Share on other sites
Advertisement
Most of the time, it's guess work, since there are a lot of factors that can come into play. But in general, there is an equation that will give you stop-point, given a few input parameters :

- current Velocity
- target velocity (in your case, 0).
- constant Acceleration (or deceleration).

- will give you, the time taken to reach the target velocity, as well as the distance.



take the euler integration

(v1 - vo) = a * (t1 - t0)
dv = a * dt

-> dt = dv / a = (0 - v) / a = -v/a
-> aka the time it will take, given a constant deceleration, to reach velocity 0.

(p1 - p0) = dv.dt + 0.5 * a.dt^2
dp = dv.(-dv/a) + 0.5 * dv^2 / a
dp = -dv^2 / a + 0.5 * dv^2 / a
dp = dv^2 / a * (-1 + 0.5) =
dp = -dv^2 / 2.a

say, a car travelling at 20 m/s (72 km/h, or 45 mph).
car decelerate constantly at 0.8g ~= 8 m/s^2 (very good brakes).

It will take the car 2.5s to get to a stand still, and 25 meters.

for a more flexible system, [google] boids and autonomous steering behaviour.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!