- Home /

# Vector3.Lerp does not linearly interpolate, any ideas?

I've had this little idea for an FPS game and following the success with the few people that played the last game I finished I decided to go into it with a light heart. However, I've come up against a couple of problems with it; my Vector3.Lerps do not seem to work as intended. I know it is something I've done and it's almost certainly blindingly obvious to anyone else but I can't see what's wrong and so some help would be very much appreciated.

Relevant Code:

```
public Vector3 editingPosition;
public Vector3 originalPosition;
public Vector3 editingRotation;
public float editingFOV = 30.0f;
public float editingFOVAll = 45.0f;
public float defaultFOV = 60.0f;
public float timeToTake = 0.3f;
if(!isEditing){
transform.localPosition = Vector3.Lerp(originalPosition, editingPosition, 1f * Time.deltaTime * (timeToTake * 10));
transform.localRotation = Quaternion.Slerp(Quaternion.Euler (0,5.8f,0), Quaternion.Euler(editingRotation), 1f * Time.deltaTime * (timeToTake*10));
Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, defaultFOV, 1f * Time.deltaTime * (timeToTake * 10));
weaponCamera.fieldOfView = Mathf.Lerp (weaponCamera.fieldOfView, defaultFOV, 1f * Time.deltaTime * (timeToTake * 10));
}
else{
transform.localPosition = Vector3.Lerp(editingPosition, originalPosition, 1f * Time.deltaTime * (timeToTake * 10));
transform.localRotation = Quaternion.Slerp(Quaternion.Euler(editingRotation), Quaternion.Euler (0,5.8f,0), 1f * Time.deltaTime * (timeToTake*10));
Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, editingFOVAll, 1f * Time.deltaTime * (timeToTake * 10));
weaponCamera.fieldOfView = Mathf.Lerp (weaponCamera.fieldOfView, editingFOV, 1f * Time.deltaTime * (timeToTake * 10));
}
```

The problems I'm having is that the Vector3.Lerp isn't moving the model at all (All the values are set in the editor to the correct places) and, though I took this from my other script where the Vector3.Lerp worked, however, it does not linearly interpolate but rather jump to the second location.

N.B. The Quaternion.Slerp and the Mathf.Lerp work as intended.

Any help to point out my errors would be very much appreciated.

Thanks.

**Answer** by robertbu
·
May 15, 2014 at 08:05 PM

None of your Lerps/Slerps are linear. All are used in a non-traditional fashion. Lerp is intended to be used by passing a value between 0 and 1 as the last parameter. So typically a timer is used and some ever-increasing fraction is used as the last parameter. But code like your is the predominant way that Lerp/Slerp is used in questions and answers on UA. Instaed of a linear movement, it produces a eased movement towards the goal. It works by passing the same fraction as the last parameter, but it updates the first parameter to be the current position/setting. The result is that at each call it moves the same fraction towards the goal, but since the distance is shrinking the same fraction is an ever decreasing distance. The result is an eased movement towards the goal. And while it gets close to the goal quickly, it runs for a long time before reaching the goal.

Taking a look at line 10 you have:

```
transform.localPosition = Vector3.Lerp(originalPosition, editingPosition, 1f * Time.deltaTime * (timeToTake * 10));
```

If you look at your first parameter, you are using 'originalPositon'. I'm not sure if this does what you want, but following the pattern of this kind of Lerp(), it should be:

```
transform.localPosition = Vector3.Lerp(transform.localPosition, editingPosition, 1f * Time.deltaTime * (timeToTake * 10));
```

Note, unless you are 'editingRotation' somewhere, I don't understand why your Slerp() is working. Also note, that if you really want a linear movement, you can use Vector3.MoveTowards() instead of Lerp().

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.