-
Member
How to check if a unit is in line of sight
Does anybody know how to tell if a unit is within the player's line of sight? I can't find any client functions. Potentially recast/detour could be used for raycasting? But I'd rather do something else if it's available.
-
Originally Posted by
klee946
Does anybody know how to tell if a unit is within the player's line of sight? I can't find any client functions. Potentially recast/detour could be used for raycasting? But I'd rather do something else if it's available.
You can do a raycast in-game. Use World::Intersect, it accommodates all in-game geometry rather than using a recast mesh (most likely not entirely accurate.)
Code:
public enum IntersectFlags {
None,
DoodadCollision = 0x00000001,
DoodadRender = 0x00000002,
WmoCollision = 0x00000010,
WmoRender = 0x00000020,
WmoNoCamCollision = 0x00000040,
Terrain = 0x00000100,
IgnoreWmoDoodad = 0x00002000,
LiquidWaterWalkable = 0x00010000,
LiquidAll = 0x00020000,
Cull = 0x00080000,
EntityCollision = 0x00100000,
EntityRender = 0x00200000,
Collision = DoodadCollision | WmoCollision | Terrain | EntityCollision,
LineOfSight = WmoCollision | EntityCollision
}
...
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private delegate bool World__Intersect_t(ref Vector3 start, ref Vector3 end, ref Vector3 hitPosition, ref float hitDistance, IntersectFlags flags);
...
public static bool TestCollide(Vector3 start, Vector3 end, IntersectFlags flags) {
var hitPosition = Vector3.Zero;
var hitDistance = 1f; // Must be initialized to 1.
return World__Intersect(ref start, ref end, ref hitPosition, ref hitDistance, flags);
}
Last edited by Jadd; 06-28-2017 at 07:57 PM.
-
Post Thanks / Like - 4 Thanks
-
Member
Sweet, I should have enough info to solve this. Thanks!
-
Active Member
From which points does the game check line of sight?
Base, middle or top of the bounding boxes?
I have seen issues with some dungeon bosses that seem to float in the air when players fight them.
Ultraxion in Dragon Soul, Helya and her Tentacles in maw of souls, Naraxus in Neltharions Lair.
The one in ulduar i think had the same problem.
Krosus in Nighthold on the other hand seems to be the same, standing on a ledge, partially visible, but has no issues.
In which way are these mobs special in terms of los?
-
Originally Posted by
blamani
From which points does the game check line of sight?
Base, middle or top of the bounding boxes?
I have seen issues with some dungeon bosses that seem to float in the air when players fight them.
Ultraxion in Dragon Soul, Helya and her Tentacles in maw of souls, Naraxus in Neltharions Lair.
The one in ulduar i think had the same problem.
Krosus in Nighthold on the other hand seems to be the same, standing on a ledge, partially visible, but has no issues.
In which way are these mobs special in terms of los?
The calculation is done on the server, so impossible to say without just testing what works. I use CGObject_C::GetObjectDisplayHeight from each unit as an offset for both the source and target traceline test. I'm not sure if it works 100%, but it works good enough for me to not bother testing different scenarios by hand.
-
Member
What address are you using for World__Intersect?
Edit:
I think I got it working at address 0x69BFF0.
Last edited by klee946; 07-09-2017 at 07:40 PM.
-
Elite User
Originally Posted by
Jadd
You can do a raycast in-game. Use World::Intersect, it accommodates all in-game geometry rather than using a recast mesh (most likely not entirely accurate.)
Code:
public enum IntersectFlags {
None,
DoodadCollision = 0x00000001,
DoodadRender = 0x00000002,
WmoCollision = 0x00000010,
WmoRender = 0x00000020,
WmoNoCamCollision = 0x00000040,
Terrain = 0x00000100,
IgnoreWmoDoodad = 0x00002000,
LiquidWaterWalkable = 0x00010000,
LiquidAll = 0x00020000,
Cull = 0x00080000,
EntityCollision = 0x00100000,
EntityRender = 0x00200000,
Collision = DoodadCollision | WmoCollision | Terrain | EntityCollision,
LineOfSight = WmoCollision | EntityCollision
}
...
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
private delegate bool World__Intersect_t(ref Vector3 start, ref Vector3 end, ref Vector3 hitPosition, ref float hitDistance, IntersectFlags flags);
...
public static bool TestCollide(Vector3 start, Vector3 end, IntersectFlags flags) {
var hitPosition = Vector3.Zero;
var hitDistance = 1f; // Must be initialized to 1.
return World__Intersect(ref start, ref end, ref hitPosition, ref hitDistance, flags);
}
I wonder where those flags are from
[16:15:41] Cypher: caus the CPU is a dick
[16:16:07] kynox: CPU is mad
[16:16:15] Cypher: CPU is all like
[16:16:16] Cypher: whatever, i do what i want