Iterate Vector Locations

Discussion in 'Plugin Development' started by Maximvdw, Feb 17, 2014.

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

    Maximvdw

    Hi,

    I'm a bit stuck. I want to iterate through X vector locations starting from a startlocation.

    Example:
    Location shootLocation = player.getEyeLocation();
    Vector directionVector = shootLocation.getDirection().normalize();

    I want to get all the locations within a radius of X from the shootLocation.

    PSEUDO:
    Location shootLocation = player.getEyeLocation();
    Vector directionVector = shootLocation.getDirection().normalize();
    for(Location location : directionVector){
    // ...
    }

    Best Regards,
    Maximvdw
     
  2. Offline

    AmShaegar

    All Locations? Could you be a bit more specific? All Locations would be really a lot...
     
  3. Offline

    NathanWolf

    I think a BlockIterator would work well for this (not sure?)

    Otherwise, what I do is basically:

    1. Calculate distance between the two points
    2. Calculate normalized direction vector
    3. Start at first point
    4. For (i = 0; i < distance; i++) { add direction to location)

    I have to admit I've never used a BlockIterator, but only because my plugin code predates it :\ But I think it's made to do exactly what you're doing there- line of sight from an entity.
     
Thread Status:
Not open for further replies.

Share This Page