- Home /

# Lerp in direction to certain distance

Quick question: How can I lerp an object in a certain direction, to distance amount, at a certain time, at local position?

```
public bool shift;
public Vector3 direction = new Vector3(0.7f, -0.7f, 0);
public bool speed = 2; // seconds
public float distance = 0.25f;
private float lerpTime;
void Update() {
if (shift) {
Vector3 lerpTo = // Lerp at direction to distance.
lerpTime += Time.deltaTime / speed;
transform.localPosition = Vector3.lerp(Vector3.zero, lerpTo, lerpTime);
if (transform.localPosition == lerpTo) {
lerpTime = 0;
shift = false;
}
}
}
```

**Answer** by jpierre88
·
Jan 01, 2016 at 02:47 AM

Silly me! It was simpler than I thought. Vector3 lerpTo = direction * distance;

Took me a while to figure this out even though the answer is so simple after you know, but if you want to be able to Lerp to a specific distance in any direction, you simply set the Float in the Lerp to the desired distance divided by the distance between two objects.

```
Vector3 point = Vector3.Lerp(obj1.transform.position, obj2.transform.position, desiredDistancFloat/(Vector3.Distance(obj1.transform.position, ob21.position)));
```

**Answer** by Firedan1176
·
Dec 31, 2015 at 03:21 AM

If you're simply trying to find out how far to go in a certain direction, you would simply create a Vector3 with that distance in one of the 3 axis.

`Vector3 lerpTo = new Vector3(distance, 0, 0);`

would be .25 in the x. You can replace 0 with distance if you desired, too, to make the object go diagonal.

is this what you're wanting?

Not really. I'm trying to lerp to direction Vector3(0.7f, -0.7f, 0) at distance 0.25.

**Answer** by Kiote
·
Jul 19, 2020 at 03:26 AM

Took me a while to figure this out even though the answer is so simple after you know, but if you want to be able to Lerp to a specific distance in any direction, you simply set the Float in the Lerp to the desired distance divided by the distance between two objects.

```
Vector3 point = Vector3.Lerp(obj1.transform.position, obj2.transform.position, desiredDistancFloat/(Vector3.Distance(obj1.transform.position, ob21.position)));
```

### 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.