PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Jul 02 2018, 5:46 PM PST 2 min

Lerp, short for linear interpolation, is a mathematical technique for producing intermediate states between a start and an endpoint. It is related to Articles/GUI Animations.

For a single variable, we can define

function lerp(a, b, t)
    return a * (1-t) + (b*t)
end

By definition, for all implementations of lerp:

lerp(a, b, 0) == a
lerp(a, b, 1) == b
lerp(a, b, x) == lerp(b, a, 1-x)

Two Roblox types have a lerp method:

  • DataType/Vector3 interpolates all three components as above
  • DataType/CFrame uses quaternions for rotation slerp to interpolate orientations, and linear interpolation to interpolate positions

For which the previous identities still hold:

vecA:Lerp(vecB, 0) == vecA
vecA:Lerp(vecB, 1) == vecB

cfA:lerp(cfB, 0) == cfA
cfA:lerp(cfB, 1) == cfB
Tags:
  • script
  • concept
  • lua
  • animation
  • gui