Moving object from vector A to B in 2d environment with in increments of percents

newbie picture newbie · Jun 1, 2011 · Viewed 10k times · Source

I know coordinates of vectors A and B. How can I count first point between these two vectors? First vector X is 1% of the distance between vectors A and B. So first I will move object in vector A 1% closer to vector B. So I need to calculate vector X that is new vector for object, until it reaches vector B.

Answer

aib picture aib · Jun 1, 2011

You want lerping. For reference, the basic formula is:

x = A + t * (B - A)

Where t is between 0 and 1. (Anything outside that range makes it an extrapolation.)

Check that x = A when t = 0 and x = B when t = 1.

Note that my answer doesn't mention vectors or 2D.