Check line of sight in Lua - allfoxwy/UnitXP_SP3 GitHub Wiki

  • /script local result = UnitXP("inSight", UNIT_ID, UNIT_ID);print(result);

UNIT_ID could be player, target... also GUID string "0x12345"

The 1st UNIT_ID also accept camera.

Return TRUE for in sight, FALSE for NOT in sight, NIL for error.

This function has limitation:

  • This is an expensive function. Basically it is raytracing on CPU. So it is recommended to check distance (or apply other filters such as friend/foe) before calling this function.
  • It works locally, no server communication, not precisely accurate.
  • I don't know how to read object's height, so this function treat everything as Human height.
  • As of v22, this facility has an internal cache. Continuously calling it would result in a very small delay between update. However it should improve the overall performance and should be still practically usable for Lua AddOns.