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.