Is it possible to tell if a character is standing in a shadow (is shadowed)?

Hello! .(^_^)/

I would like to ask if it’s possible to tell, via blueprints, if the player character is standing inside a shadowed area?

The thing is I am building a game with temperature (in a desert), so I would like the temperature to slightly drop once the character is walking into a large shadowed area. Just like in real life, where you would cool down by getting out of the sun.

However I am using dynamic lighting only (day night cycle), because of this I can’t use a collision box or similiar static workarounds for the shadowed areas.

Is this possible and if so, how could I achieve this via blueprints?

Thank you for your help! :slight_smile:

Hey, I’mma give you my 2 cents.

If you have just static shadows, you should be able to do that with a blueprint with a collision box. And just place your fields wherever the shadows are.

But if you have some dynamic shadows, i.e. sun changes position over time and therefore, your shadows move with it, it will get complicated, as you’ll need to calculate that in your blueprints.

Other than that, I’m not aware of a way to get that data from the rendering engine. But as I’m relatively new to UE, there might be a way that I don’t know of. :slight_smile:

Oh yes, I forgot to mention I am using dynamic shadows, that’s why I can’t use a collision box. I will update my original post. :slight_smile:

Actually, now that I think of it, you can cast rays from your sun position, to the ground. And whatever those rays hit, gets “heated”.

if your character would be standing in a room, would not be hit by those rays, so it would be “cooler”. :slight_smile:

Oh that’s a great idea! But wouldn’t it cost me thousands of rays then to cast over the whole area? Hmm unless I calculate the direction from the sun position to the characters position and only use one ray.

Thank you for the tip, I will try to build a blueprint for that now. :slight_smile:

Hey, glad that helped! :smiley:

perhaps do a ray from the top (or middle of your mesh) AND the bottom. the two rays will at least then let you know that you character is at least 50% shadowed?

Yeah I was thinking about how to do being partially lit by the sun, and that’s a good idea. :slight_smile:

You can also use a raycast that goes from the sun to your character, when the raycast hits something it means your characters is behind an object aka inside a shadowed zone. I’m not sure how accurate you want this to be though, but if you want more accuracy than just the middle or head of the character’s shadow detection you can also have multiple raycasts, like one for feet, one for middle and one for head and check if any of those are ever blocked which will give a more accurate detection.

Yes, that is exactly what EU_Coxis suggested and what we have been talking about in the last posts. :stuck_out_tongue:

Oh, sorry I didn’t read through the thread. Just wanted to drop my idea just in case it could be helpful. :slight_smile:

Btw, comming up with another suggestion if you haven’t done it already.

While calculating your temperature, you could also take in account where the sun is on the sky, since while being at sunrise or sunset, the sun’s radiation would heat up objects less than while being up at noon, because the radiation waves are tangent to the planet’s surface so they scatter more in the atmosphere than they do when perpendicular. :slight_smile:

I think this would be a nice touch to your game.

Edit: Aaaand, if you got wind going on, wind cools down things. So you can get that into account as well. But maybe this gets too complicated for what you actually want. I have no idea, but hope it helps.

I know, I was just a bit sarcastic. Thank you for your feedback. :slight_smile:

Ah yes, I am using a time system to determine where the suns locations is. And then I will use certain time zones (like 18:00 - 20:00) to set a temperature.
Probably I will make it that at 20:00 there is a certain base temperature, and from 18:00 it starts going towards that.

I want to use wind later on (I am still in prototyping phase), but I have to see if it get’s too complicated indeed. Although it would be really interesting. :slight_smile:

The raycast idea is a good one and quite efficient.