# Braking algorithms for AI

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

## 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 on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015492
×