[solved] Simple walkTo(x, y) method for starter game.

Hey JGO, I’m trying to write a method that simulates the player walking to the clicked position on the screen. (Game tiles stationary atm)

What I have now produces a buggy system where the player is usually over the targetX by a few or under, this results in the player bouncing. (Happens for x and y -> bounces both ways)

Can anyone recommend a better way to do this than what I have below?


		// If a destination has been flagged.
		if (walkToX != -1 && walkToY != -1) {

			if (playerY <= walkToY) {
				playerY += 5;
			} else if (playerY >= walkToY) {
				playerY -= 5;
			}
			if (playerX <= walkToX) {
				playerX += 5;
			} else if (playerX >= walkToX) {
				playerX -= 5;
			}
		}

Thanks guys :slight_smile: