# LerpUnclamped

> Interpolates linearly between two vectors, allowing extrapolation beyond the end points.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## LerpUnclamped(Vector3, Vector3, float)

Interpolates linearly between two vectors, allowing extrapolation beyond the end points.

```csharp
public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): Start value. This value is returned when `t = 0`.**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): End value. This value is returned when `t = 1`.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Value used to interpolate between or beyond `a` and `b`.

### Returns

| Type                                                              | Description                                                                                  |
| ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | Interpolated value. This value always lies on a line that passes through points `a` and `b`. |

### Remarks

Unclamped linear interpolation allows for values of `t` less than zero or greater than one, such that the returned vector can lie outside of the points `a` and `b`.

This method is useful for finding a point some constant rate along the line through two endpoints. For example, to move an object gradually beyond and through those points.

The returned value **V** equals

**V** = **A** + (**B** − **A**) × t

The method interpolates between points `a` and `b`, such that:

* When `t` ≤ 0, this method returns a vector that points along the line through `a` and `b` but in front of `a`.
* When 0 \< `t` \< 1, this method returns a vector that points along the line between `a` and `b`. The distance along the line corresponds to the fraction represented by `t`.
* When `t` > 1, this this method returns a vector that points along the line through `a` and `b` but beyond `b`.

```csharp
// This example creates three primitive cubes. Using linear interpolation, one cube moves along the line that passes through the others.
// Because the interpolation is not clamped to the start and end points, the moving cube passes the end cube after the interpolation frame limit is reached.    
// Attach this script to any GameObject in your scene. 

using UnityEngine;

public class LerpUnclampedExample : MonoBehaviour
{
    // Number of frames in which to completely interpolate between the positions
    int interpolationFramesCount = 300; 
    int elapsedFrames = 0;

    // Number of frames to reset the moving cube to the start position
    int maxFrameReset = 900;

    GameObject CubeStart;
    GameObject CubeEnd;
    GameObject CubeMove;


    void Start()
    {
        // Create the cubes
        CubeStart = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeStart.transform.position = new Vector3(-5,0,0);

        CubeEnd = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeEnd.transform.position = new Vector3(5,0,0);

        CubeMove = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeMove.transform.position =  CubeStart.transform.position;
    }

    void Update()
    {
        float interpolationRatio = (float)elapsedFrames / interpolationFramesCount;

        // Interpolate position of the moving cube, based on the ratio of elapsed frames
        CubeMove.transform.position = Vector3.LerpUnclamped(CubeStart.transform.position, CubeEnd.transform.position, interpolationRatio);

        // Reset elapsedFrames to zero after it reaches maxFrameReset
        elapsedFrames = (elapsedFrames + 1) % (maxFrameReset);  

    }
}
```

Additional Resources: [Vector3.Lerp](/engine/6000.7/script-reference/unityengine/vector3/lerp.md) [Vector3.SlerpUnclamped](/engine/6000.7/script-reference/unityengine/vector3/slerpunclamped.md)

## LerpUnclamped(Vector3, Vector3, float)

Interpolates linearly between two vectors, allowing extrapolation beyond the end points.

```csharp
public static Vector3 LerpUnclamped(in Vector3 a, in Vector3 b, float t)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): Start value. This value is returned when `t = 0`.**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): End value. This value is returned when `t = 1`.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Value used to interpolate between or beyond `a` and `b`.

### Returns

| Type                                                              | Description                                                                                  |
| ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| [Vector3](/engine/6000.7/script-reference/unityengine/vector3.md) | Interpolated value. This value always lies on a line that passes through points `a` and `b`. |

### Remarks

Unclamped linear interpolation allows for values of `t` less than zero or greater than one, such that the returned vector can lie outside of the points `a` and `b`.

This method is useful for finding a point some constant rate along the line through two endpoints. For example, to move an object gradually beyond and through those points.

The returned value **V** equals

**V** = **A** + (**B** − **A**) × t

The method interpolates between points `a` and `b`, such that:

* When `t` ≤ 0, this method returns a vector that points along the line through `a` and `b` but in front of `a`.
* When 0 \< `t` \< 1, this method returns a vector that points along the line between `a` and `b`. The distance along the line corresponds to the fraction represented by `t`.
* When `t` > 1, this this method returns a vector that points along the line through `a` and `b` but beyond `b`.

```csharp
// This example creates three primitive cubes. Using linear interpolation, one cube moves along the line that passes through the others.
// Because the interpolation is not clamped to the start and end points, the moving cube passes the end cube after the interpolation frame limit is reached.    
// Attach this script to any GameObject in your scene. 

using UnityEngine;

public class LerpUnclampedExample : MonoBehaviour
{
    // Number of frames in which to completely interpolate between the positions
    int interpolationFramesCount = 300; 
    int elapsedFrames = 0;

    // Number of frames to reset the moving cube to the start position
    int maxFrameReset = 900;

    GameObject CubeStart;
    GameObject CubeEnd;
    GameObject CubeMove;


    void Start()
    {
        // Create the cubes
        CubeStart = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeStart.transform.position = new Vector3(-5,0,0);

        CubeEnd = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeEnd.transform.position = new Vector3(5,0,0);

        CubeMove = GameObject.CreatePrimitive(PrimitiveType.Cube);
        CubeMove.transform.position =  CubeStart.transform.position;
    }

    void Update()
    {
        float interpolationRatio = (float)elapsedFrames / interpolationFramesCount;

        // Interpolate position of the moving cube, based on the ratio of elapsed frames
        CubeMove.transform.position = Vector3.LerpUnclamped(CubeStart.transform.position, CubeEnd.transform.position, interpolationRatio);

        // Reset elapsedFrames to zero after it reaches maxFrameReset
        elapsedFrames = (elapsedFrames + 1) % (maxFrameReset);  

    }
}
```

Additional Resources: [Vector3.Lerp](/engine/6000.7/script-reference/unityengine/vector3/lerp.md) [Vector3.SlerpUnclamped](/engine/6000.7/script-reference/unityengine/vector3/slerpunclamped.md)
