Getting all the blocks between two locations/entities

Discussion in 'Plugin Development' started by Hoolean, Dec 3, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Hoolean

    Exactly what the title suggests :D
     
  2. Offline

    leiger

    Just iterate through them all.

    Get the minimum and maximum X, and the minimum/maximum Z value.

    Depending on how you want to handle Y values, you may want to do the same thing there (min/max based on entity locations).

    Code:
    // For x = xMin to xMax
        // For y = yMin to yMax
            // For z = zMin to zMax
                // Get block at this location (x, y, z)
    
    Depending on what you plan to do with those blocks, you may wish to store information about them into a container of some sort (e.g. array/list).
     
  3. Offline

    Latzafs

    You know. I just made a for loop for all of this, such as for(x=1;x<=input;x++) but what you did was so much easier. ._.
     
  4. Offline

    Hoolean

    That will give a cube with one corner at the 1st location and the other corner at the other location. I want to just have a line (I'm checking if there is a wall in inbetween two locations)
     
  5. Offline

    fireblast709

    in 3 dimensions, a line is a cube as well. In the case it is a line, a cube with width and height 1 and depth = line length
     
  6. Offline

    leiger


    Then you will want to do some collision checking.

    Use Bresenham's line algorithm (use Google for sample code), and for each point on the line check if it intersects with your wall.
     
Thread Status:
Not open for further replies.

Share This Page