# -Solved- Ray collision, how to have objects detect the ray?

I’m making a first-person game that has a mechanic of picking up items and using them to help progress, the current system has a rectangle extending form he front of the player’s face, and the items detect that collision. This makes it possible to get items through walls, this is obviously bad…

I learned that Rays can be used to detect only the first object. I can’t figure out how to get the object to carry out an action, seeing as rays are sensors, and objects can’t detect them. And there are multiple items on the scene, I can’t have the ray send objects to every item on the scene, that’d be too laggy.

Image of the player rig:

There is nothing analogous to a collision sensor for rays. You’ll have to write a bit of Python to get the actual object hit by the ray.

I demonstrate the basics of doing that in the attached example (use arrow keys to rotate the caster).

### Attachments

ray_demo.blend (444 KB)

Objects can’t detect a ray.
Casting a ray is an algorithm that test intersections of an imaginary line to faces in the scene.

Finally it is the same as you looking at your monitor. The monitor does not care if you look, it will not recognize if you look, not is there any physically interaction from your look to the monitor (but the other way around). Philosophers might question if the monitor is still there when you do not look. If you think this is a ridiculous thought … in a game the monitor indeed will not be there … it saves processing time ;).

Nevertheless a ray is a measurement. If you want to let the detected object know they are detected … you have to do that via Python.

I do not really understand why you want the objects detect the camera/avatar. Wouldn’t it be more efficient when the camera/avatar detects the objects?

I can’t figure out what your intention or the problem is…

Can you first outline what it is you want to do in the game? Just to get the item the player is looking at? Python for that is very simple.

I learned that Rays can be used to detect only the first object.

Raycast can be used in X-ray mode where it looks through objects to find one that meets your criteria (property/material). You can also disable raycasting collision for objects you don’t need them for which makes things more straight forward.

I need the player to be able to pick up items by hitting e while they are looking at the item. But another forum user has showed me an example to do this with python.