Friday, March 25, 2016

Let There Be Light

I created darkness levels in Penguin Pete today, upon suggestion of Tim.

This of course meant that I needed to start working with light, an area I tend to dislike in the first place. As with anything in Unity, there's a steep learning curve. Additionally, there is much less info for 2d Unity lighting, than for 3d. This made things even more... interesting.

I first needed to darken the entire scene. After a brief online read, I started out by simply adjusting the "Ambient Intensity" of the entire scene in the Lighting Window.


This seemed to work for everyone else online. But wait... it's not that simple in 2d Unity. I had been thwarted. I then began adjusting every possible control in the Lighting Window. It logically seemed to me that the """Lighting""" window should effect some aspect of the """light""" of the world.

As with most things, button-mashing doesn't fix the problem. I began another drawn out googling session. Had I not come across this random post, I would probably still be googling.

Apparently, the default Materials for all 2d sprites are not effected by light, which explains why my button mashing didn't work. Once I gave each item the correct Material, I was golden.  Or black, as it were.

Now I simply needed to add a light component, and attach it to the penguin as the only light in a dark world. Interestingly, Unity's light components are designed for a 3d world, but they still effect a 2d world upon intersection.



This ended up being a problem for me. Initially, my light was not illuminating anything. It turns out that my z index was off, so my light wasn't showing on the 2d plain. Once that was adjusted, I wrote all the necessary code, and voila! Dark levels!




Additional pro tip:
I discovered this little jewel during my adventures. If you want to give your users (or yourself) chronic visual dysfunction, just turn up the ambient light setting to max level. The result is displayed below.



On the bright side (pun intended), an intense subjugation period of 30+ minutes would definitely work as effective eye bleach after coming across an especially unattractive creature of the female homosapien variety.

2 comments:

  1. The idea of a dark level with all those vile seals is just plain horrifying. You are a dastardly man, Daniel Cossins, a dastardly man.

    I tried to play with the lighting for some effect (I wanted to put a spot light behind the star in the middle of our map and have it shine through it (Hey, it sounded good at the time)) and gave up pretty fast.

    I think I'm doing something wrong when playing Penguin Pete. I never get to the rocket pack stage...

    ReplyDelete
  2. Yes, I now am having nightmares now about hungry, terrifying seals. I'm gonna start seeing a therapist about it next week.

    By the way, I hadn't updated the web build until recently. It should be out now.

    And I had never thought about playing some of the other games. What a grand idea! I'll have to do that tomorrow

    ReplyDelete