Checking if an object is being looked at

Avatar
Soundlogic
169 Posts
Posted Jun 05, 2011
I decompiled valves map to try to figure out how to check if an object is being looked at, and I copied the entity they used, edited it slightly, but it doesn't seem to be working. If anyone could give me some advice on what is wrong with my setup I would appreciate it.
Thank You,
Sound Logic
Attachments
looktest.vmf
0.02 MB 49 downloads
Advertisement
Registered users don’t see ads! Register now!
Avatar
yohoat9
274 Posts
Posted Jun 05, 2011
Replied 14 minutes later
Lol, I got the vmf and put it in the maps folder, then realized that I already have a map called looktest XD
Avatar
taboo54
34 Posts
Posted Jun 05, 2011
Replied 48 minutes later
To set this up, all you need is two entities. A brush based entity http://developer.valvesoftware.com/wiki/Trigger_look and the entity that you want the player to look at.

To trigger an output, the player must be in the volume, and looking at the entity in the "look target" box.

I've provided an example map, because it's easier than explaining it in detail. Just make sure you learn something from it. :thumbup:

Attachments
lookatmap.vmf
0.02 MB 48 downloads
Avatar
KenJeKenny!?
238 Posts
Posted Jun 05, 2011
Replied 4 minutes later
@ taboo54;

If he won't... I will! :smile:

Avatar
Soundlogic
169 Posts
Posted Jun 06, 2011
Replied 21 hours later
I know how to do that, but the goal I am trying to achieve is to be able to tell if the player is looking at an object. Not just have a trigger the first time they look, but to be able to tell at any given moment if they are looking at the object. Make sense?
Avatar
Kasc
77 Posts
Posted Jun 06, 2011
Replied 2 hours later
As far as I can tell (I've not done any testing, only looked at the wiki) but...

Create a trigger look that sets the value of a info_branch, named player_is_looking to the value of 1.

The trick is in changing this back 0 when the player is no longer looking. If the trigger_look does not automatically refire once it is triggered then you could kill the brush and respawn another with a point_template.

i.e A trigger_look is in place, when a player is looking at the area the trigger sets the logic_branch to one, then kills itself, then spawns another of itself, and resets a timer which if left to run, will set the logic_branch back to 0.

I can make an example if this isn't making any sense to you.

Avatar
NocturnalGhost
200 Posts
Posted Jun 06, 2011
Replied 39 minutes later

The trigger_look is capable of what you are asking, although this feature seems to be undocumented on the wiki.

Firstly, you need to uncheck "fire once" in the flags, and check "clients". Now, the part that is undocumented is the fact that, when fire once is not checked, the "timeout" value resets the triger, and cancels any pending outputs. So, to give an example, a light (let's call it "red_light") that comes on when you look at the correct place:

"Look target" to the object you want to look at (obviously)
"Look time" to "0", so the triggering is instant
"Field of view" to "0.0" (which equates to 90 degrees, change this as needed)
"Timeout" to 0.5 (again, change to suit. Ignore the description, when used in this manner it is the refire rate of the trigger)

Now, for the outputs:
OnTrigger>>Target "red_light">>via input"Turn On">>delay "0"
OnTrigger>>Target "red_light">>via input"Turn Off">>delay "0.6"

Now, as you can see, the light is set to turn back off after 0.6 seconds. However, this doesn't happen, since the trigger resets itself and refires after 0.5 seconds. If you aren't looking in the right direction at that time, the sequence is allowed to complete, and the light turns off.

I'm not sure how taxing it is to the game to have the trigger performing in this manner, but it works okay in testing. I'll attach the vmf. I used a light so you would be able to see it's effect even when you aren't directly looking at it, but i see no reason why it wouldn't work with other entities.

look_light_test.vmf
Attachments
look_light_test.vmf
0.01 MB 44 downloads
Avatar
Soundlogic
169 Posts
Posted Jun 06, 2011
Replied 12 minutes later
Wow. Thanks. That is clever. Someone should really put that in the wiki. That is really clever. Thank you.
Advertisement
Registered users don’t see ads! Register now!
Avatar
Kasc
77 Posts
Posted Jun 06, 2011
Replied 26 minutes later
Yep that's certainly a much cleaner method than my own :smile: I've not really been experimenting with all the different entities yet, I would like to though!