# Detect if Player is in Light Help

So I programmed a Code that helps me for the Actor (In that Case a Lamp) to detect via Line Trace if the Player is in the Range of the Light.

If he is in Range and gets hit by the Line Trace (Light), the Boolean is set to “TRUE” and if he is not in Range it’ll be “FALSE”.

So far everything works but I hit a roadblock on this one:

If I place more than one of the Actor within the Level the Player still gets damage (Through Mental Health Darkness Event) because even if he is in the Light the “FALSE” Bool on the other Actors overwrite the “TRUE” Boolean.

I don’t know how I can find the Solution to that Problem.

Here is the other half of the Code

Maybe this won’t solve but to progress step by step, can you first try changing that “or” node with an “and”?

Also, not related but why don’t you use event tick instead of creating a loop after event begin play?

(post deleted by author)

I tried AND and it still doesn’t work sadly, only when the Lights are close to eachother, but they both would be in Range so both are TRUE.

I didn’t used Event Tick because I don’t want to ask frequently if the player is in range.

Make the line traces longer then. I wanted you to do that to know if it would work that way, so I think the problem is not in that function you call afterwards.

You can increase the range of the line traces by getting the angle from the player to the actor according to the world (globally the (x = 1, y = 0, z = 0) unit vector is considered to be pointing at 0 degrees), create that unit vector using the “make vector” node, drag a “rotate vector” node out of it, plug in that angle to rotate it accordingly, multiply the result how long you want it to be, add the actor’s location to it and plug that into the “end” pin of your line trace node.

I visualized it, here it is:

About your hesitation on using event tick, you see maybe now you’re not having the computer questioning that, but you also make it run the same thing another way. You don’t need to worry about that, it won’t reduce performance.

Hey @TranorVespucci,
Welcome to the forum.

Can I suggest the following approach:

Use a counter in the player. Every line trace that hits the player increments that counter. If the counter is at 0 - damage the player at the start of the next tick. (you will have to wait for all lights to make their trace - that’s way “at the start of the next tick”)

Better yet you can use a float instead of the counter. That way you can add how much light is hitting the player based on the distance to the light. If the total light is below a certain threshold - damage the player.

Hope this helps.

PS. You can use SetTimerByEvent to plug your Light detection. You can also use the TickEvent of the object and set the tick interval to 1 second. (the last one assumes that the blueprints are in the light and it has nothing else to do on tick)

I made an project a while ago that basically covers this mechanic

It uses auto adjusted sphere volumes that adapt to point and spot lights with a drain mechanic in darkness and regen mechanic in light

character

spot

omni

Interface

1 Like