Search Unity

Question Flashlight Glitch

Discussion in 'Image Effects' started by m_daniel26, Apr 28, 2023.

  1. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    The project I'm currently working on incorporates a flashlight mechanic, which I'm generating with a prefab model flashlight and a spotlight attached with a range of 100, spot angle 50, intensity and indirect multiplier both set to 1. Sticking with the default white for the color for now, though will probably play around with more of a yellowish color later. As I've been testing it out, I've noticed a few bugs that I can't figure out how to get around, so hoping someone might have some insight! I'm working in Unity 2021.3.20f1.
    1. The closer I am to an object, the smaller the lighted area becomes, which yeah, it technically should, but this seems extreme. See image 1 attached - that tiny little white dot on the wall is the light beam, and doesn't even line up with where the flashlight is pointing (though, I'll settle for living with that last bit, if I can get the area issue fixed).
    2. There are certain walls where if I shine the flashlight on one section of the wall, the entire wall lights up instead of just the one section. See images 2, 3, & 4 attached - in image 2, you can see that the wall on the left is fully lit up, even though the beam is only slightly touching that wall; image 3 shows where I moved the beam slightly to the right, so that it is not touching the left, and the wall is in its natural darkened state. Image 4 shows an even weirder iteration of this glitch (but demonstrates it pretty well) - On the roof, I actually have 3 different cubes lined up to construct the roof in order to make the whole for the ventilation shaft. The two thinner cubes (to the right and left of the vent shaft) I used the same texture but with a different material and tiling in order to make the three cubes blend more naturally. But when the light is shined on either of the thinner cubes, it lights up the entire cube (I only shined it on the left cube in this example for illustration). The only difference between the two materials used is the tiling (and of course their scaling), yet one lights up entirely, and one doesn't light up at all! WTF??
    3. Lastly (and this is probably the one that bugs me the most), part of the game involves crawling through the aforementioned vent shaft (if there's going to be a vent shaft in the game, obviously you're going to be crawling through it at some point, lol). However, I have noticed that when in the vent and utilizing the flashlight, the direction I am facing affects how well the flashlight lights my path. EG, if I'm facing "North" or "West", it doesn't light my way at all (in image 5 attached, I am facing due "North"). But if I'm facing "South" or "East," it lights my way perfectly (image 6 is me standing in the exact same position as image 5, but facing due "South."
    Any ideas anyone might have on figuring out what I'm doing wrong on these (3 is probably the most crucial that I want to resolve, where as 1&2 are annoying but I could live with them if I have to).
     

    Attached Files:

  2. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    Here is image 6 which I could not attach above.
     

    Attached Files:

  3. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    One additional thing I tried for troubleshooting: I swapped out a Point Light in place of the Spot Light. Obviously doesn't create the desired flashlight look, but just tried it to see how it affected these glitches. The texture/material issue with the walls went away, but the North-South/East-West issue did not (BTW, I realize I should have specified in my original post that the NS/EW issue isn't JUST in the vent shaft, it's just most noticeable in that area, due to the confined space and lack of other light).

    Not sure what exactly that means or how to use that to pinpoint how to fix the Spot Light issue, but maybe someone will get some ideas from that.
     
  4. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    I fixed the first issue, by moving the Spot Light a little further back, closer to the player, so that one's good. Issues 2&3 are still active though, and can't figure out a way around them.
     
  5. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    Playing around with shaders I was able to fix issue #2, so all that's left to figure out is issue #3 - if anyone has any ideas on that one, please let me know.