Jump to content

Walker With Basic Obstacle Handling


Swizzbeat

Recommended Posts

    public Position nextTile(Position path[], int skipDist) {
        int dist = -1, closest = -1;
        for (int i = path.length - 1; i >= 0; i--) {
            Position tile = path[i];
            int d = script.map.distance(tile);
            if (d <= 16 && (d < dist || dist == -1)) { //<---- was edited
                dist = d;
                closest = i;
            }
        }
        
        int feasibleTileIndex = -1;
        
        for (int i = closest; i < path.length; i++) {
            if (script.map.distance(path[i]) <= skipDist) {
                feasibleTileIndex = i;
            } else {
                break;
            }
        }

		return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
    }

i added in one line, because for the next tile method it will get the furthest tile in the path, but sometime it picks a tile that maybe like 3-5 time out of minimap rang and just get stuck there so i added a quick boolean that will help check to see if it can reach tile.  

Link to comment
Share on other sites

    public Position nextTile(Position path[], int skipDist) {
        int dist = -1, closest = -1;
        for (int i = path.length - 1; i >= 0; i--) {
            Position tile = path[i];
            int d = script.map.distance(tile);
            if (d <= 16 && (d < dist || dist == -1)) { //<---- was edited
                dist = d;
                closest = i;
            }
        }
        
        int feasibleTileIndex = -1;
        
        for (int i = closest; i < path.length; i++) {
            if (script.map.distance(path[i]) <= skipDist) {
                feasibleTileIndex = i;
            } else {
                break;
            }
        }

		return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
    }

i added in one line, because for the next tile method it will get the furthest tile in the path, but sometime it picks a tile that maybe like 3-5 time out of minimap rang and just get stuck there so i added a quick boolean that will help check to see if it can reach tile.  

 

You should probably add it to the loop which actually grabs the next tile to walk to. The first loop just gets the closest position to your current position as a starting point.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...