Friday, May 17, 2024
HomeGame Developmentphysics - How hard to brake to perfectly smoothly reach the destination?

physics – How hard to brake to perfectly smoothly reach the destination?


When an object brakes with a constant deceleration, then its velocity over time looks like this:

Velocity over time

Distance traveled is velocity multiplied with time. So the orange area in the graph above actually represents the distance traveled. And the area of a right triangle is half that of a square with the same width and height. So:

$$ distance = (velocity * time) / 2 $$

And the time it takes to get from the current velocity to 0 is the velocity divided by the deceleration, so:

$$ distance = (velocity * velocity / deceleration) / 2 $$

But we know the distance and need the deceleration. So we need to rearrange the formula:

$$ distance * deceleration = (velocity * velocity ) / 2 $$
$$ deceleration = (velocity * velocity ) / ( 2 * distance ) $$

There you have it.🡅🡅🡅

However, this formula assumes that you are using a physics engine that is able to model acceleration by integration. Some physics engines unfortunately just assume that velocities are constant during physics ticks and then changes the velocity between ticks. So in reality the deceleration curve in your engine might actually look like this:

Velocity by time in a tick-based game engine

The math still mostly works out over the long term, but can lead to inaccurate results in the short-term. Especially when the engine operates on a variable tick-rate. So if you are using a physics engine that works like that, you might receive results that are “good enough” but not perfectly accurate.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments