Scripts / Entity in player's field of view

Author
Message
TGPEG
Game Guru Backer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location: Bristol, United Kingdom
Posted: 18th Jun 2016 22:44
Hi everyone.



I write following the end of four hours of testing. What the above code does is about 10% of the way there.

What I want is to be able to tell whether the player is looking at a specific entity before offering the option to activate it or proceed to the next step. The current system offers no such command, therefore my idea was to work out the angle of the object compared to the player's position horizontally, then compare that to the angle of the player camera (which you can get). I've done that with a bit of trigonometry based on the known position of the player and the position of the entity.

So far I've got it working on the x axis only where I can tell my position in relation to the entity to within 90 degrees one way or the other. That's as far as I can get right now.

The theory would then be to take the angle the player is currently facing at and then subtract that from the entity's bearing in relation to the player, and if the result is less than 10 degrees or radians or whatever, offer the opportunity to press a button or have an event just happen. If you were looking to be even more precise you'd also do it vertically (or on the y axis) as well so the camera would have to be pointing roughly at the entity.

Unfortunately that's all just theory - can anyone tell me how to get this working properly or am I barking up the wrong tree completely?
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 18th Jun 2016 22:59
check out the first few links here, i have already written some handy functions for you
https://forum.game-guru.com/thread/207801#msg2479478
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
TGPEG
Game Guru Backer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location: Bristol, United Kingdom
Posted: 18th Jun 2016 23:20
Ah, you did what I was trying to do, except properly.

Thanks very much!
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 19th Jun 2016 14:04
Hope you don't mind but I've 'Lua'ised the function and added comments explaining why.

I've also changed it to return a Boolean value so it is simpler to use, i.e:

if PlayerLookingAt(e) then ....

or

if PlayerLookingAt (e, 2000, 20) then ....

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

Attachments

Login to view attachments
PM

Login to post a reply

Server time is: 2024-12-22 18:31:29
Your offset time is: 2024-12-22 18:31:29