[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:

http://www.policyalmanac.org/games/aStarTutorial.htm

Looks interesting, will spend some time reading it, thanks :slight_smile:

A star is the best but difficult(ish) to implement due to the amount of objects and positions you have to handle along with implementing it into iteration. Dijistka is better to start with , mainly because its simpler. The step up from the dijistka is the heuristic path finding algorithm , once you learn both of these you can understand how a star works because dijistka recognises how far it is from the player but it searches everywhere evenly however the heuristic goes straight to the destination however in most situations you end up with a path twice as long. its an interseting topic . Not to sure about other decent algorithsm if anyone has a some it would be cool to look at.

@Icass

What are you talking about, he already implemented A*, he just doens’t know how to move the character along the path.

Lcass…
anyways it was just a general rant to anyone looking thats it

I solved it :slight_smile:
Finally implemented it into my game after about 8 hours of vigorous coding and debugging but hey, all done so yay.