# How to get a time value depending on the distance? (No velocity involved, tween)

Hello, I have a math question here I could probably solve when I get refreshed, but I’m out of ideas right now.

I have a tween, and in that tween it will move the position of Part1 to Part2, I want to change the tween’s time depending on the Part1 - Part2 length so that the tween isn’t super slow if the parts are close to each other or super fast if they are far away.

I’d check for the magnitude, but would I need to check for alpha or something like that?

you can use the magnitude and your own equation for speed (studs/second probably)
s.t. magnitude of 5, speed of 2 studs/second → 5/(2/1) = 2.5 seconds to complete

1 Like

But I don’t know how to apply “relativity” to know an object’s instant speed (and I’m also using tweenservice)
The only way I’d know to check for the speed is once the object has already moved not before

You can use `speed = distance / time` that you will have learnt in school. We can rearrange for time like so: `time = distance / speed`. Distance is `(Part1.Position - Part2.Position).Magnitude` and speed is a predefined constant:

``````local Speed: number = 1 -- Studs per second
local Time: number = (Part1.Position - Part2.Position).Magnitude / Speed
``````

Simply plug the time into the `TweenInfo` and away you go.
Edit: Got the order wrong in the rearrangement sorry.

2 Likes

You’re defining your own value for it, it’s so that an object of magnitude 10 takes the same time per stud to get to the goal as one with a magnitude of 5

1 Like

alright thanks guys both of you have helped me, the only solution I could come in my mind was to get the delta of position divided by the delta of time but that would be done after the object has been moved (so I couldn’t change the tween)

but thanks bobby for the speed variable I didn’t think about that

Both of you are correct but I can just tick one answer

You mistook something, time is not == to distance * speed, because then the more speed you have the more you’d take travelling

it’s:

T = D/V