How to check if the player is being hit by light

In my game I need to have it so that I have a boolean that always tells me if the character is being hit by light (is casting a shadow). Is there a better way of doing that except manually adding triggers for darkness or lighting and checking for them? I don’t have any lighting in my scene but don’t think I really need the lighting itself, just something to show where is light and where is dark (lines in the air between light and dark).

The problem here is how do you define “being hit by lighting”?

The simplest way to do this I’m guessing would be trigger colliders. Set your flag to true on enter and to false on exit.

Yeah, I need a bit more context to offer any advice.

My mistake, not lighting but light. I want it so when my player is casting a shadow (getting hit by light and on the ground) he can pop out his shadow and use it as a second character. I just need a way of checking if he’s casting a shadow

1 Like

Is this 2D game? Side or top-down view? Are you creating the shadow somehow? If so, then I could guess, you should know exactly when you are creating them, right?

Maintain a connection from your server to the player’s client. Ping it periodically. On unexpected connection loss (possibly caused by the EM interference that a lightning strike generates), look up the geographical location of the player based on their IP and cross reference it with live lightning strike data from some academical source (like http://wwlln.net). If you got a match, then there’s a big chance that your player got hit by lightning. Of course, you might get false positives, like, for example, the lightning striking the player’s nearby fibre optic relay. But, depending on your use case, it might still be good enough.

4 Likes

Okay I am gonna be the one to give you serious advice here:

What you want to make sounds pretty complicated, but the simplest way to do it would be to use collision objects, which detecting if two objects are touching. Collision objects don’t have to have sprites (so they can be invisible).

1 Like

But honestly; my advice is that you look at some tutorials and the manuals and start with something a little simpler.

1 Like

:rofl:

2 Likes

@lonskyne you must give us a bit of context and what you already have, so we could imagine what is this about, because, as you can see there is some misunderstanding :confused: maybe you want something like this?

So you could probably check a simple ray cast between a lightsource and your player? If there is any obstacle between light and player, you could assume, that the player is in the shadow. :wink:

2 Likes

My advice would be that you learn collision objects before you learn raycasting!