class PathBot { float x,y,z; float speed, prox; Node wp, pos; ArrayList path = new ArrayList(); int pathIndex = 0; Pathfinder ai; PathBot(Pathfinder ai, Node pos, float speed){ moveTo(pos); this.ai = ai; this.pos = pos; this.speed = speed; this.prox = 5; } void getPath(Node target){ if(target == pos || !target.walkable) return; path = ai.aStar(pos, target); if(path.size() == 1) return; pathIndex = path.size()-2; wp = (Node)path.get(pathIndex); } float dist(Node n){ if(z == 0.0f && n.z == 0.0f){ return (float)Math.sqrt(((x - n.x)*(x - n.x))+((y - n.y)*(y - n.y))); } else { return (float)Math.sqrt(((x - n.x)*(x - n.x))+((y - n.y)*(y - n.y))+((z - n.z)*(z - n.z))); } } void moveTo(Node n){ this.x = n.x; this.y = n.y; this.z = n.z; } void move(){ if(wp == null || wp == pos) return; if(dist(wp) -1){ pathIndex--; wp = (Node)path.get(pathIndex); } } if(abs(x - wp.x) > prox * 0.5) x += wp.x < x ? -speed : speed; if(abs(y - wp.y) > prox * 0.5) y += wp.y < y ? -speed : speed; if(abs(z - wp.z) > prox * 0.5) z += wp.z < z ? -speed : speed; } }