Have rays ignore certain objects,

I’m firing rays with python, and wand them to collide (stop at) everything but what’s on a certain list - of objects and/or properties.

Any help is appreciated.

You can assign a property that your ray will detect.
Make sure all the objects you want your ray to hit have this property.

Example:

hit = object.rayCast("Cube", "Cube2", 10, "hit", True, True, True)

Only objects with the property hit would be detected. The second last true in the parameters enables x ray, which allows the ray to go through objects that don’t have the property.

I know, but I want the ray to be stopped, just not by a few specified objects.

Thanks, though.

For the opposite (ignoring certain objects/properties) there isn’t a good way of doing this as raycasts in BGE are scene-wide.

One rather expensive workaround is to raycast in a loop. Should it hit an object you wish to ignore, call another ray from the hit object with from=hit point, to=the original source, and distance=a negative value.
Example:
result = hitObject.rayCast(source, hitPoint, -100)

I used a poorly-designed implementation of this for armor piercing bullets in our BGMC 10 entry. They were stopped after hitting the second wall.

Ok, just call a list of objects hit with a ray, sort by distance, then ignore objects with property X, build a new list?

Those specified objects don’t need to have the property that allows them to be detected then and the x ray would pass right through them…

that is true :smiley:

Ahhh! I see. The way my code is set up now, it just detects if the ray hits anything, (is positive) but if I changed it so it would only continue if it hit an object with the name I’m searching for, this would work!

Thanks Linkxgl!