How to tell object that I,m Looking to it?

I’m making my third person shooter. i want that object (radio, TV, gun,…) knows that i’m looking to it. How to do this using python?:spin:


You can use a radar sensor on an empty parented to the head of you character.
The distance parameter will be the maximum distance of view of the character and the angle parameter will be the viewing angle of the character.

oops! double post.

A better way is to use a ray sensor to look for the object with a particular property and the ray_sensor.hitObject to locate the object and try sending a message to the object that player is looking into it.

But what if the object is behind your head ? The ray will still hit it but you can’t see it. How can you test if the object is in your field of vision ?

My sugestion is for you to attach an object to the camera, filling all its vision field (cone or pyramid). Then make it ghost and give it a view property.
For the objects add a collision detection for the view property!
I think that should do it.

The radar sensor does basically the same thing. The only difference is a radar sensor works like a near sensor. The collision sensor only detects collision with faces, it will not trigger if an object is inside an other.

I wanted to make it using ray sensor, but there is a problem as plop said. Radar sensor is very laggy, So i think the best way is use python. I think we must find an angle between object and player looking way. expample: if angle > 0 then player not looking to object
if angle == 0 then player is looking to object.
we need to calculate some formula. Please help!

I do not think pure python is the best way. You need to find a configuration with radar or ray sensors.

For me, ray sensor is working fine for what you want

Radar sensors should not be laggy. YoFrankie game uses a lot of them without problem :confused:

As said NeonDelice, pure python is probably not a good solution until you are an experienced programmer. You can’t just write if angle == 0 because positions and angles are floats and it will never equals exactly 0.00000. You would also have to calculate the positions of every objects in the camera referential to get the angle and… sounds like a complex way to do something simple ^^

You can try to use only a ray sensor but the smaller you object is, the more difficult it will be to get it hit by the ray.

I do´n’t seem to understand, you want to tell the object that is been looked at or do you want the player to know he’s looking at an object? Your diagram seemed to suggest the first option. For that I don’t think ray or radar can help you . Instead of an empty piramid, add some faces inside…

i realy need script. object and player both or jus one can know where im looking.

Also i waiting for a python script

ok i solved that. im gonna use radar sensor. Also im waiting for script

A script ? If the radar sensor works, why do you want a script ?

radar sensor not every time detects, and a little laggy

The only thing that you need in python would be to know the object that is been detected :

lastObjectDetected = radarSensor.hitObject
Then you test with a sort of manager the consequences

And may be you can pulse the radar sensor ?