Formula to go from Point A to Point B

963 Views Asked by At

I have an entity running at a certain speed, I need to go from point A to point B. What is the formula for that? I need to be able to go to point B no matter the position of point A.

enter image description here

I'm making a game, basically point B is the moving player and Point A is another entity. There is no specific distance because the player is moving, and the world that they are moving in is basically a graph. Point A will need to follow Point B. But let say the distance between them is 10.

1

There are 1 best solutions below

0
On BEST ANSWER

If points $A$ and $B$ are fixed and $A$ has co-ordinates $(x_A, y_A)$ and $B$ has co-ordinates $(x_B, y_B)$ then the parameterised line

$x(t) = (1-t)x_A + tx_B\\y(t)= (1-t)y_A + ty_B$

will go from $A$ at $t=0$ to $B$ at $t=1$. If you actually want to arrive at $B$ at $t=t_1$ instead of $t=1$ then you can just change the scale as follows:

$\displaystyle x(t)= (1-\frac t {t_1})x_A + \frac t {t_1}x_B\\\displaystyle y(t)= (1-\frac t {t_1})y_A + \frac t {t_1}y_B$

If your object travels at constant speed $s$ and the distance between $A$ and $B$ is $d$ then $t_1=\frac d s$ and the parameterised line becomes

$\displaystyle x(t)= (1-\frac {st} {d})x_A + \frac {st} {d}x_B\\\displaystyle y(t)= (1-\frac {st} {d})y_A + \frac {st} {d}y_B$