how to have a character know if they're inside a shadow?

So, i wanted to make a character be able to detect shadows so it can use a mechanic.
one problem i dont know how to…
i’ve seen one post about this but it never went to depth about it for me, who’s still a bit too green when it comes to coding, to understand it.
any advice or links for this problem?

1 Like

You could do a line trace from the character to the light. If it hits, you’re not in shadow.

It’s probably a bit more complex than that, but the basic idea is ok :slight_smile:

( example is coming, having a technical issue… )

1 Like

Ok, this

As you can see, I get a ray ‘coming from the sun’

image

When the ray hits my cube, it’s ok, when it doesn’t, the cube turns pink

shadow

Lot of caveats here :slight_smile:

  1. This code assumes you’re using the standard lighting setup.
  2. By default, the player won’t block traces ( why I used the cube ), but you could change the player collision, or add extra components etc
  3. It only works if the sun is hitting/not hitting the head, in this case.
  4. Important

image

2 Likes

ohhh okay, this makes a lot more sense.
thanks a lot, this gives me a better understand on how exactly I can get this mechanic to work to where its fun for players now :grin:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.