public double getDirectionLength(String dir, double minPathLength) {
        int xDiff = coordX - targetX;
        int yDiff = coordY - targetY;
        int tempDiff = 0;
        double pathLength = 0;

        if(dir.equals("up")) {
            tempDiff = yDiff-1;
            pathLength = Math.sqrt(xDiff*xDiff + tempDiff*tempDiff);
            if(minPathLength > pathLength) {
                desiredVelX = 0;
                desiredVelY = -1;
                minPathLength = pathLength;
            }
        } else if(dir.equals("down")) {
            tempDiff = yDiff+1;
            pathLength = Math.sqrt(xDiff*xDiff + tempDiff*tempDiff);
            if(minPathLength > pathLength) {
                desiredVelX = 0;
                desiredVelY = 1;
                minPathLength = pathLength;
            }
        } else if(dir.equals("left")) {
            tempDiff = xDiff-1;
            pathLength = Math.sqrt(tempDiff*tempDiff + yDiff*yDiff);
            if(minPathLength > pathLength) {
                desiredVelX = -1;
                desiredVelY = 0;
                minPathLength = pathLength;
            }
        } else if(dir.equals("right")) {
            tempDiff = xDiff+1;
            pathLength = Math.sqrt(tempDiff*tempDiff + yDiff*yDiff);
            if(minPathLength > pathLength) {
                desiredVelX = 1;
                desiredVelY = 0;
                minPathLength = pathLength;
            }
        }
        return minPathLength;
    }