1.16.x Getting all entities within a cylinder radius from a center location

Discussion in 'Spigot Plugin Development' started by HarleySwtfus, Sep 16, 2020.

  1. If I have center location "loc", I want to get all mobs within a radius of X in a cylinder area (ignoring Y axis)
    How can I do this? I am useless with maths
     
  2. Get the entities of the world the loc resides in and then filter out those where the distance (Location#distance(Location)) is greater than the radius of the cylinder. To optimize, calculate the squared location and filter all entities out where that is greater than the desired distance squared.
     
    #2 Schottky, Sep 16, 2020
    Last edited: Sep 16, 2020
    • Useful Useful x 2
  3. Very useful, thank you for this.
     
  4. drives_a_ford

    Moderator

    This is not a cylinder but a sphere.

    You'd get all the entities in the world.
    And then, for a point of with x=Xm, z=Zm and radius R, you'd check if an entity's X and Z satisfy (X - Xm)^2 + (Z - Zm)^2 <= R^2.
     
    #4 drives_a_ford, Sep 16, 2020
    Last edited: Sep 16, 2020
    • Agree Agree x 2
  5. Squared ;)
     
    #5 Schottky, Sep 16, 2020
    Last edited: Sep 16, 2020
    • Agree Agree x 1