Can you detect shadow?

I’m tinkering with stealth game ideas at the moment and really wanted to allow the player or enemy to “hide” in the dynamic shadow(sun lamp) so I’ve searched for a while and came to believe bge has no such native support, so here is an odd approach I’d like to ask, is it viable to calculate the region or volume of space where shadow is present? I wanted to do this so that the player/enemy could tell when it is going inside one of those shadow region.

All I could think of is this pseudo code at the moment

direction_light = object.position - light.position 
angle_light = object.axis.dot(light.axis)
volume_object = object.lenght*width*height
shadow = direction_light ? angle_light ? volume_object

I’m terrible at math but I hope it explains something about that idea, thanx

After some tests, I’m beginning to yield some limited results, here’s the blend

GamePlay_Trial_ver_1.blend (854 KB)GamePlay_Trial_ver_1.blend (854 KB)

I tried to get the vector of face normal to player position and then dot it with the light to check their parallelity to determine where the shadows will be and it seems doable… sort of…

Why are you casting a ray to every single object in the scene? All you should have to do is cast a ray from the light to the player. No fancy linear algebra required. If the ray hits the player, then you know it’s not in the shadow of another object. If it doesn’t hit the player, then the player is in a shadow.

Note that this simplified method won’t take account situations in which only part of the player is in a shadow. If you want to handle those situations differently, you’ll need to cast multiple rays from the light to certain boundary points on the player, but the same basic concept applies.

Why are you casting a ray to every single object in the scene?

To be honest, I have no idea… I’ve never used raycast before and I thought I should cast it in all direction and get the normal of anything nearby

All you should have to do is cast a ray from the light to the player. No fancy linear algebra required. If the ray hits the player, then you know it’s not in the shadow of another object. If it doesn’t hit the player, the the player is in a shadow.

Thanks, that solves a lot of thing, what the hell was I trying to do there lol