What the heck is lerping, when would I use it, and what does it do?

  1. What do you want to achieve? I would like to know what lerping is, how I would use it, and when would be a good time to use it.

  2. What is the issue? Currently, there is no issue, I am just extremely curious on how I would use lerping, since I am making a hockey game, and I saw the word lerp pop up.

  3. What solutions have you tried so far? I have looked around the dev forum trying to figure out what it was. The only thing I found was some weird ahh formula

1 Like

Lerping is useful if you want to get/set the value of something between two points.

For example:

local red, green = Color3.new(1, 0, 0), Color3.new(0, 1, 0)
local colorInBetween = red:Lerp(green, 0.5)

The value of colorInBetween is 50% of the way between red and green.

1 Like

How do you think this would be useful, or how can I use it to make more realistic ice skating physics?

I answered a similar question like this before:

In Summary:

  • Lerp is just short for “Linear Interpolation”
  • Interpolation is a way to transition between A and B.
  • Linear means a straight path (which means only 2 points will be used)

For your case, you would probably just use physics.

1 Like

Physics isn’t realistic enough for me. It has too slow of an acceleration and I don’t like the way it stops. Thanks for the reply tho. I do have 1 question. How could I use this to move a puck. Is there a more efficient way to slide the puck. (sorry if my grammar is bad; daylight saving got me messed up)

Lerp can be essential if you intend on creating your own physics. Most of the time you’d do this because Roblox physics can be unpredictable, and you can’t risk having that.

Say for example, I have a puck that can be hit by players so that it moves to a specific location.
You could leave it to Roblox physics to handle the movement of the puck for you, but you might come across some artifacts (eg, the puck jitters, or straightup doesn’t even move because of physics sleep).

Or, you can find out where a puck’s starting location, and where it would end up based on the force (magnitude and direction) that is exerted on the puck.
Then use lerp to move that puck from its starting location to its final location.

Think of it as tweening, but even better because you have a higher degree of control (eg: what if the puck is hit while it is still travelling, or if it hits a wall).

2 Likes

I see there are 3 variables in the lerp function: lerp(a,b,t). What is the variable t representing?

a + (b - a) * t

a = Point A
b = Point B
t = Time Position

Time when lerping works as percentage point between A and B, only going from 0 to 1. 0 representing 0% and 1 representing 100%. if t was .6, then I would be traveling 60% of the way to Point B from Point A.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.