[solved] Newb implementing pathfinding into my game

Hey JGO, I’m at the point in my game where I know what I’d like to do.

I have a game map rendered of 32x32 tiles. (Tile.java)
I also have a few Map Objects (Bushes, plants etc) these aren’t centered on tiles. (MapObject.java)

I have implemented game world movement via:
W,A,S,D
Arrow Keys
Right clicking mouse/holding (my pathfinding).

I’d like to implement legit pathfinding, so my player will walk around objects on his way to the destination.
(And if pathfinding includes the fastest route, that also :D)

At the moment here is my method of walking to a destination: (right clicking game world)


// invoke our walkingQue
if (rightClickDown) {
	walkTo(mouseX, mouseY);
}

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

	// Handle the moving of our y first.
	if (playerY < walkToY && playerY + Player.WALKING_VELOCITY <= walkToY) {
		playerY += Player.WALKING_VELOCITY;
	} else if (playerY > walkToY && playerY - Player.WALKING_VELOCITY >= walkToY) {
		playerY -= Player.WALKING_VELOCITY;
	}

	// Handle the moving of our x next.
	if (playerX < walkToX && playerX + Player.WALKING_VELOCITY <= walkToX) {
		playerX += Player.WALKING_VELOCITY;
	} else if (playerX > walkToX && playerX - Player.WALKING_VELOCITY >= walkToX) {
		playerX -= Player.WALKING_VELOCITY;
	}	
}

I’m a newb, never before implemented pathfinding of this sort, so all help/feedbacks appreciated, thanks :slight_smile: