Lerping positions by studs

I’m trying to lerp a position 16 studs closer to another position, and I can’t figure out what the alpha should be

local studsToMove = 16
local positionA = Vector3.new(0, 0, 0)
local positionB = Vector3.new(25, 0, 25) --(Goal)
local lerpAlpha = ???

local lerpedPosition = positionA:Lerp(positionB, lerpAlpha)
print(lerpedPosition) -- (8, 0, 8)

also needs to not overlerp e.g if there is only 5 studs remaining it shouldn’t overlerp by 11

I’m pretty sure this is simple, but my brain isn’t working properly

Moving 16 studs in the direction of the origin to 25, 0, 25 is not actually going to give you (8, 0, 8), it would actually give you approximately (11, 0, 11) because the vector is going in a diagonal direction. You can read up on Vectors to understand this

I’m not sure if (8, 0, 8) would be your desired results, but if you actually want to move 16 studs in the direction of (25, 0, 25) from the origin, here’s how you would calculate alpha, or the lerp percentage:

local studs = 16
local mag = (a - b).Magnitude
local lerpAlpha = studs / mag
2 Likes