# (theoretical) Ray with recast?

ok, so a hardcoded or scripted ray function with recast, that irradiated through a set of rules for the recast somehow?

ie light bouncing, and picking up color, on each bounce or?

or a bullet going through multiple layers of objects, and then subtracting damage etc from each layer it pierced?

but somehow wrapped neatly so game/logic can handle it? …?

(thinking about it, creating a no collision item, that cast a ray, then moved there, then cast again the next frame based on rules may be the best option)

You can use recursion with a custom function using rayCastTo() and it’s hitPosition and checking for some criteria (no further objects to pierce) to stop the recursion.

You could also add an elongated cube (static, ghost) as the ray, then detect which objects are colliding with it, then determine the distance from each of those objects to the Player to determine which “layer” it is.

I did something similar long time ago using vector.reflect(normal), but I never tried to make it recursive.
Quick attempt:

``````
from math import sqrt
def reflectingRay(obj, startpoint, vector, distance):
ray = obj.rayCast(startpoint, startpoint+(vector*distance), 0, "", 1)
if ray[0]:
dist = distance - sqrt((ray[1]-startpoint)*(ray[1]-startpoint))
reflectionVect = vector.reflect(ray[2])
return reflectingRay(obj, ray[1], reflectionvect, dist)
return ray

``````

Note: this is untested, I wrote it quickly from my phone.

Edit: You may have to append the hit points ordered in a list so you can use/visualize the path of the ray.

I think this would be great for destructable environments and destructable humanoids.