Im trying to make a ray return to me the things it hits:
It seems I have my script set up right but it will return only the top plane or the objects its pointing at. Id like the ray to return all the objects it passes through. I can only get mine to return the 1st it hits.
Would someone mind looking and see what im doing wrong.
Thanks for any help
ray.blend (346 KB)
The rayCast and rayCastTo methods won’t return a list of objects, only the first object hit. One way to get more objects would be to cast a new ray from the hit point on the first object in the same direction as the first ray. You could continue doing this as long as you want or until you don’t hit any more objects.
I would do it like this:
def rayCastTunnel(gobj, vec_from, vec_to):
""" Returns a list of objects intersected by ray """
hit_obj, hit_pos, _ = gobj.rayCast(vec_to, vec_from)
return [hit_obj] + rayCastTunnel(gobj, hit_pos, vec_to)
ray_tunnel.blend (333 KB)