Both are a position, the catch is it has to use a for loop and doesn't just go to point b, it slowly moves there. I know this, just I have overthought it and I can't think straight.
It's useful to think about problems involving vectors relative to some nice point.
For this problem, think relative to start
.
Relative to start
, stop
is stop - start
.
Thus as we travel we have to go from Vector3.new()
to stop - start
relative to start
.
The simplest thing that goes from nothing to a value is a line: this is a simple case of linear interpolation. You go 5%, 10%, 15%, 20%, etc, just by multiplying your progress:
for t = 0, 1, 0.03 do local movement = (stop - start) * t local position = start + movement wait() end
With this method, it will always take exactly 1 second to get from start
to stop
, no matter how far or close they are. Depending on your application, that may be what you want, but for actual motion, it probably isn't.
A simple solution is to adjust the rate inversely to the distance:
local speed = 10 -- studs / second local distance = (stop - start).magnitude local rate = 0.03 / distance * speed for t = 0, 1, rate do -- same as before