I'm trying to make an image move towards another point. I only have the current X/Y and the destination X/Y + Speed.
That's it.
public void Draw(SpriteBatch batch, int goalX, int goalY){
destX = goalX - posX;
destY = goalY - posY;
dist = Math.sqrt(destX * destX + destY * destY);
destX = destX / dist;
destY = destY / dist;
posX += destX * this.speed;
posY += destY * this.speed;
batch.draw(img, posX, posY);
}
This is my code, it kinda moves towards the object, but it moves past the object to a certain distance and then starts spazzing out for some reason.
The other point is also moving, just so you know.
Anybody can help me with this?