## How to calculate the stopping distance of a wheel collider?

I have an 'AI' bus in my game that needs to pull over occasionally at a bus stop. What I want to do is change the acceleration and brake force based on the stopping distance of the bus. I don't want to simply use the distance between the bus stop and the bus because each time the bus pulls over, it could be traveling at a different speed. Right now it uses the distance between the bus stop and the bus. It doesn't really work well though because if a bus is traveling faster, it will take a longer distance to stop and will likely go past the bus stop. Same thing if it were going slower. How do I calculate the stopping distance my bus will take to come to a complete stop?

## Solutions/Answers:

### Answer 1:

Let’s say that at some point in time you have the current speed `v0`

of your bus, which is at some position `x0`

, and it needs to stop at position `xs`

(s stands for stop).

TL;DR: You have to exert the following force `f`

on the bus:

```
f = 0.5 * m * v0^2 / (x0 - xs)
```

where `m`

is the mass of the bus.

Details:

The easiest way is to exert a constant force that will drive the bus to a parabolic (in time) curve ending exactly at the bus stop.

The equation for the position `x`

at time `t`

, and for the velocity `v`

are

```
x = x0 + v0 * t + 0.5 * a * t^2
v = v0 + a* t
```

where `a`

is the acceleration, which is what we want to calculate.

From the second equation, get `t`

as a function of `v`

, and plug into the first equation. In this way, you eliminate `t`

and find the equation for `x`

as function of `v`

:

```
x = x0 + 0.5 * (v^2 - v0^2) / a
```

Now *impose* that at `v = 0`

you want `x = xs`

, and solve for `a`

. You get

```
a = 0.5 * v0^2 / (x0 - xs)
```

from which you get the force by multiplying with the mass `m`

.

### Answer 2:

I ended up using a simple speed-distance-time calculation, and a velocity calculation. This is the code I used:

```
float time = ((distance / currentSpeed) / timeFactor);
float acceleration = (-currentSpeed / time) / vFactor;
v = acceleration;
```

`timeFactor`

and `vFactor`

are just arbitrary values, which happened to be 1 and 15 respectively.

This may not work for most other people however as this was quite specific to my code.

## References

- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport