A* AStar Algorithm follow path

Hey,
I’m working on a SimTower clone, and have implemented an a star algorithm successfully, BUT I got huge problems following the path I get from the algo. I got units which can move in that “tower”, and each unit gets an own path as an ArrayList containing waypoints. The problem is, that these waypoints are coordinates from a two dimensional array, which I created on the flow from the information my tower gives. I didn’t implemented my tower tile based, that is not cool… :frowning: however I have to convert all tower information into an 2dim Array. I think there is no mistake. The problem is to follow the path…


x += (Floor.convertToPixelX(way.get(waycount).x) - x); //moving that unit, not with delta time yet.... works, but creepy

if (Floor.convertToIndexX(x) == way.get(waycount).x && Floor.convertToIndexX(y) == way.get(waycount).y) {
waycount--;  //waycount starts with the highest index... the fist part of the way
}

I dont need a 100% solution for this. I need an idea how to implement it better, and make it even work. How would you do this? If you interessted in my Waypoint class, let me know, maybe the whole implementation is crap :frowning:

Well, I cannot completely understand whats your problem, but if you use aStar in a not tile based System, you could add a waypoint grid though and make each waypoint passable if you can reach every directly surrounding waypoint from it (no obstacle on that way) or not if not.

Hi, thanks for the answer. The problem lies in the “walking” through those points… the algorithm and grid is fine :wink:

This is how I got so far, after starting this topic:


int mul = 0;
	public void update(int delta) {
		if (waycount >= 0) {
			if (waycount >= 1 && way.get(waycount-1) == null) {
				waycount--;
			} else if(waycount >= 1 && way.get(waycount-1) != null) {
				if ((way.get(waycount-1).x - way.get(waycount).x) < 0) {
					mul = -1;
				} else if ((way.get(waycount-1).x - way.get(waycount).x) > 0) {
					mul = 1;
				} else if ((way.get(waycount-1).x - way.get(waycount).x) == 0) {
					waycount--;
				}
			}
			
			x += mul * Timer.getInstance().getMovementSpeed() * delta;
			
			if((mul < 0 && Floor.convertToIndexX(x) <= way.get(waycount).x) || (mul > 0 && Floor.convertToIndexX(x) >= way.get(waycount).x) ) {
				waycount--;
			}
		} else {
			if (!arrived) {
				x = Floor.convertToPixelX(way.get(0).x);
				arrived = true;
			}
		}
	}

First I try to determine which direction I have to choose, -1 or 1… This does not work everytime… however ::slight_smile:

I was also working with aStar ftft a few weeks ago.
Just managed pathusing by if(nextWaypoint.x == x-1) goLeft() (roughly that way)
But maybe thats not yet perfect, there is a bug somewhere…