Sitemap

Linear Interpolation — Unity

3 min readNov 22, 2025

--

In the previous article, I wrote about the Look At function in Unity.

This article will look into Linear Interpolation, also known as Lerp.

What is Lerp?

Lerp is an in-between two points calculation that continues until the destination is met.

For example, 1,2,3. 50% of 3 is 1.5 (2) half way in-between 1 and 3.

Lerping is good for light bulbs or lighting in general, as a half opacity light emission can lerp from 50% to full emission 100% overtime.

Additionally, Lerp is also a good function for moving to one place to another overtime.

Press enter or click to view image in full size

Lerp works best within the Update function call.

First, I’ll begin with setting up the variables for the lerp code.

Press enter or click to view image in full size

Within the Update function I’ll use the Input keys R and G to lerp from.

When I press the r key, I’ll set the isRed Boolean to true, and ensure the other values are false.

After the r key is confirmed, I’ll check for isRed as a good practice and set the lerp value for the red color.

Get Zac Bogner’s stories in your inbox

Join Medium for free to get updates from this writer.

The current light color by default will be white, where this will be the starting point to lerp from.

Using the Color.Lerp function, this is the primary method to transition from the current value to the next.

Mathf.PingPong will take in the time value and increase and decrease the time property in seconds, followed by a length.

Press enter or click to view image in full size

And here, I’ll test the Red Color Lerp. The Color Lerp Red will transition from white to red.

Press enter or click to view image in full size

Next, the code for the Green Color Lerp is basically the same, just switching the color variables defined.

Press enter or click to view image in full size

Here is the Color Green Lerp interaction when pressing the G key.

Press enter or click to view image in full size

And finally, here’s toggling through color lerp R and color lerp G for linear interpolation (lerp).

Press enter or click to view image in full size

And that's all for Linear Interpolation (Lerp) in Unity.

Stay tuned for more.

Thanks,

Zac B.

--

--

Zac Bogner
Zac Bogner

Written by Zac Bogner

Educator, Developer. Focused in Unreal Engine with other experience; Former Race Car Driver.