Scripts / Possible to Check If Player is Seen

Author
Message
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 13th Mar 2019 23:58 Edited at: 14th Mar 2019 00:21
What is the best way to easily detect if an enemy can see the player? And I dont mean by distance alone but if the player can actually be seen. Like in FPSC where we could check if the player is visible to the enemies rather than if he just happens to be within radius.

EDIT: What exactly does this global variable do? It seems to be the solution

g_Entity[e]['plrvisible'] = plrvis;

Does it depend on a certain view cone and range?

EDIT 2: this seems to be the solution:

if PlayerDist < viewrange[e] and g_Entity[e]['plrvisible'] == 1 or PlayerDist < 100 then

Though will i see a performance hit with using the plrvisible global in my if statement checks?
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Mar 2019 20:06
I find that the plrvisible value is a bit hit and miss tbh.

Instead you can use the old "if I can see him, he can see me" approach, i.e. raycast from the player in the direction of the NPC and if the hit equals the NPC objectId then he can potentially see you. (obviously if he isn't looking in your direction then he will not react but the view cone should already deal with that bit))

In reality the NPC is a capsule shape btw so you have to work out where the centre of the capsule is in relation to the player eye position to get the angles right to work out the values for the ray cast.


Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-05-18 15:50:55
Your offset time is: 2024-05-18 15:50:55