Help with detecting if player is in shadows

I’m working on something that’s half stealth and half platforming, and I need this for the stealth bits.
I already saw a thread about doing this by line casting from the directional light or something, but I need some help setting this up with Blueprint.
I already saw a tutorial on how to do this with the first person camera, so I tried it with the directional light to a third person controller with no luck.
But yeah if I could get some help with how to go about setting it up and which nodes to use, that would be cool.

Hey there (:

this is something from the Solus project if i remember and it is really easy to recreate.

You just need to know the angle of the sun. Your directional light has a Rotation. And the ForwardVector of this rotation is the direction of the sunlight. So if we multiply this with -1, we get the direction TO the sun.

Now we just need to setup a linetrace. Here is a picture from the LevelBlueprint:

I got the character and his position. Added the Base Eye Height to the Z Axis (because the Actor Location is normaly at his feet). This is the Starting point for the trace. Now i selected the Light in the Scene and right clicked in the Level Blueprint to create a direct reference to it (this is only possible in the LevelBlueprint, if you want to get a reference inside other Blueprints, you need to do a small work around, like getting all actors, or let the Level Blueprint set this Variable or something like that).

Now i get the Actor Rotation of the light and the Forward vector. I multiply it with a negativ number, because we want the opposite direction. The number defines how long the trace should be. I just took 1000. This is up to you. Then i added this direction to the Starting Point to get the End Point. So you take the Startpoint and extend it by 1000 in sunlight direction. Now if we hit something (like a ceiling) we know something is above us and we are in the shadows. if we hit nothing, we are open to the sun.

The number (1000) needs to be change for you, because it could be that your ceiling is 2000 units above the character. Then the line trace would hit nothing although you are in the shadows. But i guess you will get how to change this example for your needs.

I would also recommend to do 2 traces. One from the head and one from the feet, because if only do one trace, your character can be more than half in the sun and still count as in shadow or other way round

http://puu.sh/dH8rw/fb8752000e.jpg

:

Feel free to ask me if you need more help.

How do I get it to not draw the line? Or does it automatically do that on build?
Sorry for asking, but I’m pretty new at using UE4 so I don’t know what it can and can’t do as far as this stuff goes.

No problem (:

In the blueprint screenshot, you see the “Single Line Trace by Channel” Node. There is a dropdown menu for “Draw Debug Type”. In my screen it is set to “For Duration”. There should be an option to disable it (normaly it is!) in this drop down menu. Normaly the top most option. I just activated it, because i wanted to show you that it is really tracing in sun direction.

Very awesome answer! Thanks a lot! :slight_smile: