lerp code example

Example 1: unity lerp position

transform.position = Vector3.Lerp(transform.position, myTargetPosition.position, speed * Time.deltaTime);

Example 2: vector3.lerp

Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
//Smoothly transition between 2 locations over time, fractionOfJourney is time instance

Example 3: unity lerp

using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour
{
    // Transforms to act as start and end markers for the journey.
    public Transform startMarker;
    public Transform endMarker;    // Movement speed in units per second.
    public float speed = 1.0F;    // Time when the movement started.
    private float startTime;    // Total distance between the markers.
    private float journeyLength;    void Start()
    {
        // Keep a note of the time the movement started.
        startTime = Time.time;        // Calculate the journey length.
        journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
    }    // Move to the target end position.
    void Update()
    {
        // Distance moved equals elapsed time times speed..
        float distCovered = (Time.time - startTime) * speed;        // Fraction of journey completed equals current distance divided by total distance.
        float fractionOfJourney = distCovered / journeyLength;        // Set our position as a fraction of the distance between the markers.
        transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
    }
}

Example 4: lerp function

//lerp takes 3 parameters
//1st parameter is the start point
//2nd is the end point
//3rd is the percentage of how much distance can be covered like .5 = 50%
//example - lerp(0,10,.5) = 5
//example2 - lerp(0,5,.2) = 1