IsInShadow?

Is there a way to determine if my line trace hit is in a shadow? Or perhaps the lighting level at the location of that hit?

I know that I could use baked lighting and create a volume inside each and every shadow, but that’s not very workable and I’m wanting to use dynamic lighting (shadows in different places in the morning and evening.)

Kind of a long shot, I doubt there is anything like this, but if anyone has any ideas on how something like this might be implemented I’d love to hear any and all ideas.

Thanks

No.
Trace from the object to the light source.

I created a quick manager for this. It just detects light sources in range, traces and gets a response.

Then the character BP can have multiple checking points and get a result that you can tally up for a total “stealth”.

The problem is the cost. But the engine is just not ment to do what we want natively, so unless you plan to re-write half of it, this is the easiest way to implement it.

@MostHost_LA

Oh, now that does give me an idea.

I’m not looking for stealth, but whether the location is in shadow. I’m trying to create a mechanic that allows my character to teleport between shadows. The teleporting part is pretty simple, but the shadow part is kicking my bottom.

But if the line trace from the character hits a spot, I could then do another line trace from that spot to the light source(s), and if that second trace is blocked (or too far away) then it would be reasonable to assume that the spot is in shadow.

Thanks, I think that might work with point lights and spot lights (with the additional check to see which way the spot light are facing.) Not sure how to do it with a directional light, but I bet I can figure it out.

What is your manager called?

It’s an actor BP that gets attached to things (not a marketplace assets or anything).

The spot and point lights can be queried for intensity and distance info.
So its pretty easy to get a result.

The directional lights are always queried.

Usually there’s no need to run 2 traces.
If a light source cannot be reached you are generally in shadow with maybe a few exception like windows.

Simply make the collision a channel that the line trace won’t hit…

@MostHost_LA

RIght, so the way I want it to work is the character sends out a line trace to where ever he’s looking. If that location is in shadow (and in range,) then he can teleport to that location, if it’s not, then he can’t. I don’t see how I could get away with only one line trace. I need one from the character to the potential teleport location, and another from the potential teleport location to the light source. How do I do it with just one line trace?

Depends on setup.

Don’t trace to the potential location, just use that location as the origin of the trace towards other light sources.

If your result is valid for shadow, then trace to make sure the spot is otherwise accessibile.

You’ll likely need to check with a capsule trace to make sure the character can fit.

Regardless of if you do it first or after, the performance won’t really change much at all.

I’m assuming you are using VR for this given the “jumping” nature you want to have.

So maybe another trace is also in order to make sure you aren’t facing a wall or otherwise get the camera stuck in a situation where you cannot navigate away without turning around physically yourself (or use a controller button to turn?)
Idk. The whole VR idea gives me nausea already :stuck_out_tongue:

@MostHost_LA

No VR.

Yes, glad you mentioned the capsule trace. I hadn’t thought of that. Though I do already have the teleport mechanic working, I hadn’t actually tried to teleport into an area that’s too small to see what might happen.

How do I get the location coordinates of the potential location I’m looking at without first running a trace to that location? Say if I’m standing under one clump of trees and want to teleport to the shadows under another clump of trees 50 meters away, how do I get the coordinates of the location that’s 50 meters away to start the trace to the light source?

… and thanks for your help.

Depends on your setup.
I would go with the position under the cursor for mouse.

In first person aim, then yes a trace is probably needed. Unless you can get the world position under the cursor from that too… which i suppose you can. But you might as well trace from camera forward vector…

For directional light, don’t trace to the lights location. Instead, get the forward vector of the light, and trace from the location in the opposite direction of the forward vector.

@MostHost_LA

Thanks, for all your help. I did find ConvertMouseLocationToWorldSpace which allows me to avoid the first trace.

@NedimH

Thanks, I figured that already, but thanks. I trace the opposite of that vector and if I don’t hit anything, I assume no shadow. All that is working fine … except at night, but I’m getting that worked out as well. At night, or when the directional light vector has a negative z component, I just ignore the directional light. That makes thing a bit funky around dusk and dawn when the “sun” is blocked by landscape that’s far away but still positive z, but I’m confident that I will get it ironed out.

Hey all,

Thanks for the help. I’ve got this mess working reasonably well now. I’ve got a few issues to work out, but it’s just little things that I’m sure I’ll find solutions to.

1 Like