Hope you are all doing well, i trying to figure out how i can test if an entity can see a player in it's view atm i am using code below;

execute as @e[type=minecraft:villager,tag=Path,tag=Villager10] at @s anchored eyes facing entity @e[sort=nearest,limit=1,type=player] eyes anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run say Success

This code runs along side a villager with the tags path and Villager10. (side not i have removed AI for the villager so it wont move around)

This code works however it doesn't take into consideration if there are blocks in the way.

Dose anyone know if i am using the right method to do such a thing and if so how. Fairly new to commands like so.

Many Thanks. Dave

  • I assume you just want raycasting? In that case, I'll close this as a duplicate, that directs you to an answer. If not, please clarify what exactly you want. If it's checking for all exact hitboxes (like stairs, etc), then it would get insanely complicated. – Fabian Röling May 25 '20 at 21:43
  • Thank you for you're patience, i did try raycasting before however i just needed more experience with functions to create a loop for every specific entity with the tag so if a player is seen an output to a scoreboard can be set. Depending on the block (ie stairs ect) i will just take these as airblocks i think as in theory the enity should be able to see through these same with glass. Again Thank you very much hope you have a good day. – Dave. Jun 2 '20 at 18:27