Solved Easy method to check for line of sight between two locations.

Discussion in 'Spigot Plugin Development' started by Xemor, Jan 17, 2020.

  1. Question in the title, is there any good way of doing that between two Location objects?
     
  2. What exactly is it you are looking for?
    An Entity or a Block? Use World#rayTrace
    The distance? Use
    Code (Java):
    locA.distance(locB)
    The fastest way to go there, constraint to a certain x-z-plane? Use Dynamic Programming
     
    • Agree Agree x 1
  3. To see if there is a path of air blocks inbetween two locations. That's what I'm looking for.
     
  4. In that case, use World#rayTraceBlocks. You can define a maximum distance (that you can get from using the method described above). If RayTraceResult#getHitBlock() is null, you don't have a block in between, if the result is not null, you have a block.
     
  5. Thank you a lot