Line of Sight
Hey Folks. Bit of a diversion today, as I'm somewhat ill. Not quite sick enough to throw in the towel, but enough that I allowed myself to pursue an idea brought on by a fever dream last night.
One problem in the space prototype that I've been putting off is the question of how I'll render lights, line of sight, and user perspective. It's a ball of factors that are interrelated, and so far, I haven't found a good solution.
Up until recently, I assumed I could just use Unity's lighting system to handle both normal-mapped sprites and shadow-casting. It works, and actually looks really good when it runs. But it turns into a real pig as soon as there are many sprites and/or lights visible. Basically, any ship of about the size I want every ship to be.
So, I turned off shadow-casting, and that was that. (Performance was acceptable in exchange for a less-cool art style.)
Last night, before bed, I started tinkering with some lighting solutions. And later on, while sleeping, my mind kept wandering back to the problem. (Instead of sleeping, much to my chagrin.) I wondered if I might be able to limit the rendered geometry and lighting to what the crew can currently see, and if that might allow me to reenable the shadows on the lights. In theory, if we're only seeing a room or three at a time, instead of the whole ship (and docked ships/stations), maybe that would be sufficient?
So I put aside the heat stuff and gave it a shot. Today's image is the result of a day's work.
It certainly could be better, but that's actually not bad. And apart from some tile-walking code and some dimmer/hiding code on my items, the only other change I needed to make was to inflate my tile collision meshes from 2D quads to 3D boxes for line-of-sight raycasting. It has some pros and cons, so let's enumerate:
- Shadows - We get shadows again, which are nice to look at.
- More Lights - We also can manage more lights per ship, since fewer are running at any given time.
- More Dynamic - The scene is a bit more interesting to look at now that we have rooms visible vs. not, and some peeking views into others.
- More Tension - We can't see everything, and that's good for creating tension. E.g. "What was that bump?" "What's behind that door on this derelict?"
- Free Combat LoS - Whenever I get around to combat, I can reuse this code for line of sight/cover/etc.
- Exploration - Related to tension above, we have a reason to walk around: exploring the environment.
- Costly - This line-of-sight calculation is expensive to run, and needs to be updated whenever the viewer moves to a new tile, or an item changes modes (like a door).
- Errors - We still have some edge cases which produce visual errors, like wall corners and limited doorway peek-through.
- Multiple Crew - What do we do for multiple crew? Do we show all at once? Or just the currently-selected?
- Fog of War - How do we show areas that have never been seen vs. areas we simply cannot see right now?
And, of course, the big question remains. Are we just the captain? Or can we see with any crew member's eyes?
Overall, I think there's something useful here. The gameplay benefits alone (tension, combat, exploration) are pretty big, and there are a few ways to go about this which might solve one or more of the problems.
Tomorrow, assuming I'm better and not worse, I'll probably resume with the heater code. I may tinker with this more, as well, or perhaps I'll move on to more tools and derelict explorations. Whatever I choose, I have to admit it feels good to be surrounded in interesting problems again. Problems that each seem like they'll enhance actual gameplay/feel, and aren't just invisible plumbing.