Lonely Star is pretty far into production already, but in an effort to reach out to the indie game community I've decided to start a development log on the tigSource forums. Articles will be archived here too.
I'd never thought of a 2D, top-view game needing a cover system, but as I've expanded on the game's stealth and vision mechanics, a cover-system-shaped hole in the gameplay started to take shape.
The player can crouch to hide in foliage, move silently, and deliver sweep attacks. There's a defined class of objects that are not too high to shoot over, but still act as obstacles. That's really all it took:
This looks wrong, doesn't it? It looks like the monsters' arrows are somehow weaving through the barrels to hit you.
These should provide cover to a crouching player character. The 2D forced perspective that Lonely Star uses makes it difficult sometimes to keep the way objects collide feeling smooth, consistent, and visually understandable. But here, it helped a lot; my first idea was some complicated thing involving the Pythagorean theorem and sprite heights and cosines. But it turns out that it feels and looks right if, when an enemy's projectile passes over a low obstacle, it should be unable to hit a crouching player for the next (x) frames-- (x) being the number of frames it's traveled already.
There's a random factor involved in how far an enemy's shot "overshoots" you, and incorporating that into the cover script led to a cool effect where the shots will sometimes pass over the cover and the player and sometimes hit the cover instead.
The GIF is a little choppy here-- when the player is standing, they fire an arrow back over the barrels at the enemy.
But not every low obstacle should stop every projectile. Should a chain-link fence stop an arrow? A bullet? So I spent a long hour assigning properties to every low obstacle, deciding what each one should protect the player from. One cool thing about this is that it can superimpose cover properties on obstacles that are made of tiles, not objects (don't worry about the distinction-- if I'm doing my job right, you'll never notice)
So how exploitable is this? How much does it change the game?
Not a huge amount, not yet, which I'm happy for. The enemy AI is already smart enough to outflank a player who stays hunkered down, so there's a risk involved in popping in and out of cover to get them to waste ammo, and that risk multiplies with the number of shooters. Arrows are a limited resource for the player, and the sling can't be used from a crouching position. More testing is in order, for sure, but right now it looks like a situational option that I can grant the player that's useful without upsetting the game balance.