Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question 2D light shadow covering other light sources

Discussion in '2D' started by CptHavvock, May 26, 2023.

  1. CptHavvock

    CptHavvock

    Joined:
    Dec 30, 2021
    Posts:
    12
    Im currently trying to make a player with a vision cone, where the player can only bright a light on a small range, cannot see over obstacles, and if a place is illuminated by other light sources further away from the player's own light, they can see it.

    Most of this was easy to implement thanks to 2D lights and the 2D shadow caster, but the problem comes from this: I want that if there is an obstacle between the player and another light source, that light is covered by the shadow of the player's light.

    I tried making a linecast that simply disables the light sources if there is an obstacle inbetween, but then the illuminated parts outside of the obstacle(the player should see them) disappear too.

    I was wondering if Unity has any way to give priority to light so that a light with higher priority's shadows covers other lights. I've been poking around layers and depth masks without much luck.

    Thank you
     
  2. MaxwellTan

    MaxwellTan

    Unity Technologies

    Joined:
    Mar 3, 2022
    Posts:
    73
    Hi CptHavvock, are you able to give more example like screenshot on what would like to achieve?
     
  3. CptHavvock

    CptHavvock

    Joined:
    Dec 30, 2021
    Posts:
    12
    Hi, sorry for answering late, I just wanted to say I ended up finding this video that implemented the vision cone, and I used it to cover over the light, reaching my desired effect.
     
    MaxwellTan likes this.