D
D
DALVROT2020-05-29 20:09:34
Java
DALVROT, 2020-05-29 20:09:34

Moving point A to point B at a given speed?

Movement from point A to point B at a given speed in 2d. I saw movement with vectors, but did not understand how it works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denisca Gareev, 2020-05-29
@Denisca2828

You can use the lerp algorithm:
v0 - point A
v1 - point B
t - speed
response set as x or y

float lerp(float v0, float v1, float t) {
  return v0 + t * (v1 - v0);
}

// Precise method, which guarantees v = v1 when t = 1.
float lerp(float v0, float v1, float t) {
  return (1 - t) * v0 + t * v1;
}

I think it will not be difficult for you to convert to JAVA

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question