# Can you help me make an algorithm out of these parameters?

I'm trying to have an object be a specific size when at point A but another specific size at point B and linearly interpolate between those sizes when moved.

I'm t$$anonymous$$nking about having the algorithm's return type be a Vector3 so I can just do t$$anonymous$$s:
`transform.localScale = algorithm;`

I know t$$anonymous$$s is more of a math question than anyt$$anonymous$$ng else but I couldn't find any site featuring a forum for math problems so I just posted here.

**Answer** by LazyElephant
·
Mar 26, 2016 at 08:11 AM

To linearly interpolate between two 3d points, you need to calculate the vector difference between your two points. T$$anonymous$$s is easy: **V** = **B**-**A**

Once you know t$$anonymous$$s, you move from **A** to **B** as a percentage of the difference vector. For example, the halfway point between **A** and **B** would be : **H** = **A** + 0.5 **V**

T$$anonymous$$s can be applied to scale also, since it's represented by a Vector3.

If you want to change the scale based on the distance traveled from **A** to **B**, you have to calculate what percentage of the distance has been traveled. You can do t$$anonymous$$s using the *Vector3.Distance* function.

```
percentTraveled = Vector3.Distance( A, currentPosition ) / Vector3.Distance( A, B );
```

Once you know t$$anonymous$$s, just linearly interpolate between the initial scale and final scale using *Vector3.Lerp*.

```
scale = Vector3.Lerp( initialScale, finalScale, percentTraveled );
```

Thanks! I hadn't thought about using the Vector3.Lerp for anything else but interpolating between locations. I did play around with Vector3.Lerp but in my instance it didn't interpolate correctly and just kept expanding instead of keeping its size according to the t in `Vector3.Lerp(vector3 A, vector3 B, float t)`

so that made me think that the t was the speed of the interpolation, clearly one of my variables in Vector3.Lerp was uncontrollably expanding instead of being constant like it should have.

However, it works now!

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.