Task: move the object in a straight line at a constant speed in the Cartesian coordinate system (only x, y). Update rate is unstable. The speed should be close to accurate, and the object should be very close to the destination. The source and destination of the line can be anywhere.
Data: source and destination address (x0, x1, y0, y1) and the speed of an arbitrary value.
Answer: there is an answer to SO regarding this, and this is good, but it assumes that the total travel time is given.
Here is what I have:
x0 = 127;
y0 = 127;
x1 = 257;
y1 = 188;
speed = 127;
ostrich.x=x0
ostrich.y=y0
SPEED_VAR = 1000;
xDistPerIteration = (x1 - x0) / SPEED_VAR;
yDistPerIteration = (y1 - y0) / SPEED_VAR;
distanceToTravel = ;
limitX = limit1 = 0;
void update(){
while (limitX < speed && limitY < speed) {
limitX += Math.abs(xDistPerIteration);
limitY += Math.abs(yDistPerIteration);
ostrich.x += xDistPerIteration;
ostrich.y += yDistPerIteration;
}
distanceTraveled -= Math.sqrt(Math.pow(limitX, 2) + Math.pow(limitY, 2));
if (distanceTraveled <=0)
}
, 18% . , . , ?