I'm trying to make a shadow effect while using the Box2D extension by using raycasting, but it's not turning out so well. 'Single-Shape', 'Multi-Shape' or 'Custom Raycasting', neither works very solidly (See attached image).
My current set up is as follows:
And the result is this:
Always > Surface Object; Clear with color RGB(0,0,0)
Always > Start loop "Lights1" (Number of "light" ActiveObjects)
OnLoop: "Lights1" > Start loop "Lights2" (360)
OnLoop: "Lights2" ++ ID("Light")=LoopIndex("Lights1") > Box2D Object; Do Multi-Shape Ray Cast between X("Light") , Y("Light") , X("Light")+(Cos(LoopIndex("Lights2"))*100) , Y("Light")+(Cos(LoopIndex("Lights2"))*100)
OnLoop: "Lights2" ++ RaycastNumHits("Box2D Object")=0 > Surface Object; Add Polygon Point: X("Light")+(Cos(LoopIndex("Lights2"))*100) , Y("Light")+(Cos(LoopIndex("Lights2"))*100)
OnLoop: "Lights2" ++ RaycastNumHits("Box2D Object")>0 > Surface Object; Add Polygon Point: RaycastTargetX( "Box2D Object", 0) , RaycastTargetY( "Box2D Object", 0)
Always > Surface Object; Draw polygon at (0,0) with RGB(255,0,0)
The black boxes are all.. black.. boxes, with Box2D collision as such. It looks weird, I know, like there's some triangles involved - But no. It's the ray-casting that's being wonky. Notice the transparent arrows.
The red area is going to be the "negative space" of the shadow, as in, that area will be light while the area around it will be dark. Using the subtract mask effect on the surface object should work. Eventhough it seems fine (Like it's not going through the actual boxes, just clips into them) I cannot rest assured it won't be a occurring problem in the future.
So, yes, basically I'm asking openly if anyone knows a better way to accomplish this with ray-casting (It won't be squares but a much more polygonal terrain in the future). Also, on the subject of this, how exactly does the Box2D Ray-casting filter collision thing work? Like, if I want the light to shine through "glass" bodies but the bodies are still solid to other bodies? Both of these things I'd really like to know.
Thanks in beforehand!