Well you probably don't want to update the last position unless you can actually move to the new one, and there's no need for the x1 and y1 variables. I can't really see what would be causing your problem but I'd change the method to something like this:
1 2 3 4 5 6 7 8
| public void moveTo(double x, double y) { if(map.get((int)x, (int)y).walkable) { lastPos.x = pos.x; lastPos.y = pos.y; pos.x = x; pos.y = y; } } |
Have you tried printing all the variables before and after to see what's actually happening? That can be helpful.