Search Unity

How to block a light source in 2D

Discussion in '2D' started by NerdRageStudios, Aug 26, 2016.

  1. NerdRageStudios

    NerdRageStudios

    Joined:
    Nov 1, 2013
    Posts:
    167
    I am making a top down game in 2D that uses unitys lights. I had a simple system of putting walls on a higher Z layer than the floor so they are not lit by a light, which works fine, but another floor is on the other side of the room, the light will light that room too.

    I tried placing colliders, 3D cubes, Planes etc. under the wall tile but nothing seems to occlude or block the light from shining through it.

    Is there any way to achieve this?

    Here is the problem, you can see the light shining through the wall (well, technically under it)

    Screenshot 2016-08-23 18.49.16.png
    Here is how the scene is structured in terms of Z layer Screenshot 2016-08-23 18.49.51.png

    So here is an image showing how the walls are higher up on the Z plane, so they arent lit by the light, and my attempt at putting in a 3D cube to block the light, but it still passes through and lights up the sprite on the other side

    Screenshot 2016-08-23 18.50.52.png

    I assume that this is either not possible, or I am doing something very stupid indeed!

    The sprites are using the standard shader, and the light has been set to cast shadows and not cast them, makes no difference.

    Anyone have any ideas on how to solve this?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Lights are one thing, shadows are another. You basically are in need of some kind of shadow system i.e. where light is blocked by objects. Lights are calculated based on proximity to the light source and pay no attention to anything getting in the way.
     
  3. NerdRageStudios

    NerdRageStudios

    Joined:
    Nov 1, 2013
    Posts:
    167
    Thanks, apologies for the delay in reply, I've been away.

    I kind of figured that was the case, I'll try using a 3d Block under the wall, and creating a shader that recieves shadows for the sprites, and see if thats a good workaround