Can rayCast ignore specific properties?

Basically I have an object which I’m using for collision detection; it’s interfering with about fifty scripts that use rayCast(). I don’t know how to tell rayCast() to ignore it.

I tried taking another rayCast from the coordinates of the hitpoint, but that just hung the program as the first thing the ray saw was the same object again;

Now I’m wondering if the function can be told to ignore any objects with a specific property - so I could give all these invisible objects a property ‘transparent’, and rayCast would return the first object that didn’t have this property.

You can do the opposite way, hit objects with a specific properties only:

See the API: http://www.blender.org/documentation/249PythonDoc/GE/index.html
Check for Class KX_GameObject.rayCast(objto, objfrom, dist, prop, face, xray, poly)
Read the comments on xray.

Another option would be to disable collisions on objects you don’t want to collide with the ray.

I hope it helps

I had asked the same question and got some answers from Blender’s developers (read from post #6) :
http://blenderartists.org/forum/showthread.php?t=156502

That means, the answer to your question is: No, rayCast will not ignore objects with specified properties.

If you want to do it manually, instead of casting the ray from the hit position, cast if from a slightly offset position- just keep the ray’s vector, but reduce the length to something like .001, and add that to the hit position.

[edit] also, when I did this, I set a maximum number of hits, to avoid an infinite loop or lots of lag when shooting through a densely crowded area. Also, remember to get the distance from the origin and hit position, and subtract that from the length of the next ray, so that the resulting compound ray is the desired length.

Just a quick question, ray sensors works and does not work in what cases? I mean, I have some objects set to no collision. Will the ray sensor work? Will it work with static + ghost objects? Of course I can and will check myself later (when I am at home), but maybe you can already tell me what to expect

I believe no collision will not be detected by anything, same as toggling collision off on individual faces- but ghost and static should be detected by rays, near, and radar sensors- ghost shouldn’t respond to collision or touch. You might have to make sure actor is on for ray sensors to work, I can’t remember.

I’m currently trying this horrible hack:

        can_see = i.rayCastTo( i['tgt']);
        
        cthru = [];
        while can_see != None and can_see.has_key('cthru'):
            .    can_see.suspendDynamics();
            .    cthru.append(can_see);
            .    can_see = i.rayCastTo(i['tgt']);
        
        #undo our evil deeds
        for j in cthru:
            .    j.restorePhysics();

Basically, if we rayCast and find an object with the ‘cthru’ property, just disable that object and try again.

It causes a hang; is this because suspendDynamics() doesn’t actually disable collisions? If so, how do I do so?

Also, if anyone cares to comment, is there a better way of doing this code? I have no idea about how long any given operation takes for the CPU - is it incredibly stupid to be building lists of objects like that every frame?

why in principle you need ray cast? what you can always do is to get the vector, pointing at the object of interest. If you compare it with a “ray cast” vector, and they are within some error, you can say that first "fake’ ray cast vector is looking at the object

Nikolay: because we still need non-transparent objects to block the ray.

Raycast (http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_GameObject-class.html#rayCast) has an xray argument… so it’ll continue to go through things until it finds the correct property.

Can you just have a property on all objects that stop the ray? Say a property called “solid”? Or do you need to find the collision points of the objects it passes through (aka that are transparent)as well?

-Sam

Sam: That would work, and I may well end up doing it. For the moment, though, it strikes me as inelegant that 98% of objects, actors and scenery have got to have a redundant property just for the benefit of a couple of little scripts. It’s the type of setup where, ten weeks down the line I try adding some new content, forget the ‘solid’ property, and spend two days debugging unnecessarily.

However, if it becomes clear I’ve got a bottleneck and need to speed things up, that’s what I’ll have to do.

For the moment, though, I’m still trying to work out how to disable collisions in Python. Can’t see it in the API - I assume it’s possible?