Original Post
I have a dot in a blank screen. I have calculated the dot's coordinates (relative location from source component) and the mouse coordinates (after the user clicks on the screen). The constant speed of the dot is fixed at 1 pixels per tick, 60 ticks per second.
Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.
What math should I use to move the dot along the line in a more linear way?
I have here a crude path movement for the dot, now basked in your glorifying eyes:
If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.
Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.
What math should I use to move the dot along the line in a more linear way?
I have here a crude path movement for the dot, now basked in your glorifying eyes:
public void tick(MouseInputHandler input)
{
target = input.mousePosition;
if (target == null)
return;
int direction = 0;
if (position.x > target.x)
direction = -1;
else
direction = 1;
if (position.x == target.x)
direction = 0;
position.x += direction;
if (position.y > target.y)
direction = -1;
else
direction = 1;
if (position.y == target.y)
direction = 0;
position.y += direction;
}
If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.
