Is there a formula to calculate the distance travelled by a LinearVelocity decreasing in force over time?

Let’s say I have a LinearVelocity and I give it 3 seconds to travel with 4 velocity in a singular direction. Obviously, it’ll move 12 units by the time the 3 seconds is up, provided there are no other factors like friction.

But what if a Tween reduces the velocity over time to 0? Is there a formula to figure out the total distance a LinearVelocity will travel if its velocity decreases over time? I only need the formula the Linear easing style, so don’t worry about any of the other ones.

1 Like

if your acceleration is constant the total distance travelled is
velocity * time + (.5 * acceleration * time^2)

for example if:
velocity = 3
acceleration = -.5
time = 4

then
distance = 8

but for that you need to know the acceleration and you said you that you’re tweening,
i dont know anything about tweening, but assuming you dont know the acceleration, you need to figure out the acceleration which you can calculate with the initial & final velocity and the total time taken

(final velocity - initial velocity) / time

so if the end velocity is 0, the initial velocity is 3 and your time is 4 then the acceleration is -.75
then you can apply the first equation to get the distance it will have travelled, which if solved with your numbers equals 6 units of distance.

To solve this problem without being given a position function, you must use Calculus.

velocity at moment acceleration begins = v = 4
distance traveled before the acceleration = v * seconds traveled = v * 3 = 12
time to tween = t
target velocity = 0
acceleration needed (per second) = ( 0 - 4 ) / t = a
Velocity formula =
v(t) = at + v

Without Calculus you would be stuck here ^
Those who don’t know calculus are taught only taught strictly that distance = 1/2at^2 + vt
it will work here because the acceleration is constant over the input interval, this is a position formula

Integrate velocity formula with respect to t to get position formula
p(t) = (1/2)a*t^2 + vt

Example: If time to tween = 4 thus acceleration = -1 then:
p(4) - p(0) = distance, only works if velocity doesn’t change direction over the interval
(-8 + 16) - (0 + 0) = distance
8 units traveled during acceleration + 12 units traveled before that = 20 units traveled

2 Likes

Thanks, it seems to work. Though it’s less accurate with shorter pushes, but I imagine that’s because tweens update per frame, so a push that lasts 0.2s only gets 12 updates on 60 fps.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.