Given two positions, how can I determine the time needed for a BodyVelocity to go from one to the other?

I have a character positioned at (0, 0, 0), and I have a position above the character I want to move them to, let’s say this position changes depending on the circumstance.

Now let’s also say I have a constant force that I apply to the character in form of a BodyVelocity and they go up at a constant rate.

How can I find the time it’s going to take for the character to reach the position above them?

1 Like

Well, I personally wouldn’t use a body velocity, given that after removing the body velocity there may still be some momentum left over. For this situation, I would use TweenService because it’s more reliable than using a body mover.

Speed = Distance / Time, which means that Time = Distance/Speed.

You can calculate the distance through the means of using .Magnitude, and Speed is obtained from BodyVelocity.Velocity.Magnitude.

So in theory, Time = (distance of two parts) / BodyVelocity.Velocity.Magnitude

But like I said before using TweenService can give more reliable results (still uses Time = distance/speed)

1 Like

You could use a loop to find if the character’s position matches the desired end position.

For constant force, it really depends on what you want to achieve; I’d personally use TweenService and CFraming to find your calculations easier, but if you’re looking for different results, I’d use body forces to emulate real-time physics.

The only downside of using loops is that they can cause memory leaks and break performance

You can Humanoid | Roblox Creator Documentation to calculate the horizontal speed. Because speed is calculated by distance over time
s = dt
we can rewrite the equation for time. After all, we already know the distance to the point and the speed of the player. So, rewriting it we get:
t = ds

The Humanoid | Roblox Creator Documentation is the initial velocity the player jumps with, so you can calculate the jump time using:

local t = (2 * Humanoid.JumpPower)/workspace.Gravity

Edit: Oh darn. I just now realized I pretty much made a duplicate answer. Oh well!

BodyVelocity doesn’t have a property called Magnitude?

But I’m applying this with a BodyVelocity, it’s not quite the same?

Sorry; I meant BodyVelocity.Velocity.Magnitude, changed it in my original reply

I don’t really know BodyVelocity as I haven’t worked with it before. However, if you are trying the move it to the point can’t you just use BodyPosition | Roblox Creator Documentation or AlignPosition | Roblox Creator Documentation? Wouldn’t it be simpler?