Anyone experienced with using Ray sensors?

I’ve been trying to get something working using a Ray sensor that looks for a property on another object in the game engine.
What I’m trying to do is make it so only the objects in the camera view are visible. I made a small demo just to show how it sort of works.

http://jagyar.tripod.com/Files/cam_draw_view.zip
(You might have to copy and paste the url above to get it to work…someone let me know if it doesn’t work)

My problem is that I’m not sure what the ray is actually hitting when it fires. From some experimenting it seems as though it hits faces but I’ve had some strange results from it. Many times when I think the objects should be made visible by the ray sensor they don’t show up.

What I have in a more complex scene is a room with a large amount of detail but I’m using a pyramid shaped object that emits from the camera and moves along with the camera around the scene as a child of the actor. But a lot of times when the ray should be hitting and making the other objects in the room visible(the ones in the camera view as it is) they don’t come on.

So I’m wondering if anyone has another way of using the visibility actuator in order to have only the objects in the camera view visible…or give me some hints as to how to get the rays working properly. I had wondered at whether when the ray fires it only returns a true hit if it passes an odd number of faces which might explain why some of my objects don’t show up when spinning the camera around…possibly the ray is hitting an even number and this causes it to seem like it hasn’t hit anything?

Any help or comments would be greatly appreciated :slight_smile:

A ray is just a one dimensional line, and stops at the first object it hits. If you want to sense an area, use a radar sensor, which has a cone shape.

Hmm I did try using the radar sensor and have tried it again since you suggested it, but I can’t seem to get it to work. Is this how it works:? You pick which axis you wish the cone to sense and the distance you want for it?

Also how does the Ang setting correspond? It seems a little funny since if you look at the axii in 3d and if I chose the x-axis that would suggest to me that the sensor would sense the distance I had chosen on a plane 360º around the center of that object. But the radar sensor can only be set up to a max of 179.9º. So where does this angle begin and end based on where your axii are setup? I guess I also don’t see how picking one axis can result in a cone of sensing since a cone needs a width, height and depth.

Or is the cone actually set up so that the Ang gives the width of the cone from 0º (0 being aligned along the x-axis of the object?)

I’ll keep at it and hopefully I can figure it out :slight_smile:

If you look at a cross section of a cone, at the center of it, one side of it has an angle. The ang property defines this angle, the length defines the length of the cone. make sure the axis is correct, depending on the object with the ray sensor or radar sensor, the axis may not be as you expect. Make sure to turn the axis on by selecting the object with the sensor, going to edit buttons, and selecting the axis button on ther left.

The cone will start with the point of the cone at the object’s handle (the pink point), shoot down the axis, and the base of the cone will be placed out a distance equal to the dist value.

A cone can not be 180 degrees, because then it is a disc, not a cone. That’s why it only lets you go to 179.9

Since it is a cone, the bigger the distance, the wider the base will be, as the angle stays the value of the ang property.

Ok here’s what I had been doing to test the radar sensor and it doesn’t seem to work at all.

http://jagyar.tripod.com/Files/radar_test.zip (cut and paste the link again…forgot to fix it last night when I was at home so you wouldn’t have to do that…tonight I promise :P)

On no axis and with no angle was I able to get it to change the value of the property prop(which is on the cube that is located top right in top view). It’s setup to look for the property ‘hit’ which is on the pyramid shaped object but it never detects it. Does anyone know why?

EDIT:Ah ok. Thanks for that saluk. That makes sense. Still not sure why it’s not working in my radar_test file. Just as an example I made a screenshot of a cone intersecting my pyramid along the x axis…they clearly intersect so I’m not sure why the value of prop isn’t being changed…

http://img.villagephotos.com/p/2003-7/264062/intersection.JPG

Only ‘actors’ are evaluated by sensors like that, set the pyramid to an actor and it works fine. :slight_smile:

umm…don’t want to discourage you, but I did pretty much exactly the same thing (and i know others have also experimented with similar things) and unfortunately this kind of culling is slower than simply drawing all the objects anyway :-?
You can use python to cull based on distance, and that works well, but using things like radar, near and ray sensors are too slow for use in-game :frowning:

sorry to bring bad news…keep at it though, you may be the one to develop a decent system :stuck_out_tongue:

cheers
Piran

Ah bummer. I did have a semi-working one using ray sensors(not that test blend from above but a complex scene) but it seemed like it was a fluke that it worked. When I tried to change the actor the pyramid did not work anymore. I still haven’t figured out why which is why I hoped someone else knew. With the working one though I had very good results in increasing speed…especially when up close to certain objects where large amounts of detail were out of the camera view.

Well I will try changing it to dynamic and see if I can get it to work.

I’ll let you know if it affects my speed :slight_smile:

Ok major slowdown using the pyramid as an actor. The FPS has a serious drop using that way of doing object culling…most likely the same drop as using when I tried it using collisions :frowning:

Which leads me back to why I had it working with rays and had a nice increase in FPS.

I haven’t done very much python so does anyone have an example they could post that does that kind of culling?

For what you’re doing, rays just won’t work. At most a ray can only sense one object at a time, and only on an exact line from the object’s axis. If you have objects at the edges of the camera’s field of view the ray sensor would not detect them.

The angle setting for the radar sensor sets the angle in degrees on either side of the selected axis. Since a radar sensor is a type of collision sensor, it only detects objects that are set to ‘actor’ and have at least one face capable of detecting collisions, (‘collision’ button in the face paint buttons.)

Well the way I have it working is that I have a highly detailed room with several high detail objects in it. Each one of those objects sends out a ray rather than the camera sending a ray looking for all the objects. Parented to the camera I have the pyramid shaped object that has a property on it that the rays are looking for. This actually did give me a performance increase from running the scene with all the objects drawn.

What I still don’t understand are the blank spots that seem to show up when the objects should clearly be hitting the pyramid object with their rays. Increasing the range of the rays has improved it somewhat but its still not perfect. I would love to have it totally working as it would help what I’m working on immensely.

Hopefully I’ll be able to figure out how to do this with python as a few people seem to think it would be more effiecient than using the logic bricks. Hopefully I’ll get some time to start learning to use python with blender. I had really hoped for an example or 2 of someone else’s work that would cull objects that weren’t visible but no luck yet. :slight_smile:

Thanks for all the helpful suggestions and explanations so far 8)

The problem with rays is they are very expensive to process, you may be getting speed increases now but once you start using lots of objects the slow down is going to be worse with them than without.

I’ll try and post my not-very-good landscape demo tomorrow, i made a test scene using python to only draw sectors within a certain distance and that gives a nice performance increase. I was hoping someone else would post someting better, but I guess it’ll have to do :smiley:

cheers
Piran

This kind of stuff really needs to be done in the source code :frowning: But it’s still not easy to do.

Thanks saint_pill that would be appreciated…even if it doesn’t work it will still be a valuable learning tool for me :slight_smile: I figured that over the long run if I kept adding objects it would become expensive. I think I might be able to get it somewhat usable by splitting my whole thing into different scenes. Right now I have a very large building which will all be detailed down the line but as of now I only have 1 room with a lot of detail. That room is in its own scene and it runs a little slow but better than it did before I tried using rays(even though the rays don’t always draw things when they should be hitting them :P).

Ah you guys and your source code :stuck_out_tongue: Forcing me to get into it hehe…time to get back to learning to program in C++ I guess 8)