Thing is I want a small painted ball to travel from point A to Point B combined with a timer so I can see it move. I know the mathematical side of the problem and have come up with this:
int abX = pointA.getX() - bointB.getX(); // abX is the X-distance between
pointA and pointB
int abY = pointA.getY() - pointB.getY() // Y-distance between pointA & pointB
actionListener{
if(abX == 0)
{
ballX += 0;
ballY += abY/Math.abs(abY);
}
else
{
ballX += (abX/(Math.abs(abX)));
ballY += (abY/(Math.abs(abX)));
}}
The problem is that there is no 1/2 pixel og 2/3 pixel as the calculations for ballY often result therefor the ball almost always miss its target i.e pointB
I want the ball to travel in straight line from A to B no matter the distance or position of A and B.
How can I solve this?