Thursday, March 25, 2021

Project Breach #3 - "Audio, Walls, and Doors"

 Project Breach #3
"Audio, Walls, and Doors"

Welcome to the third update for Project Breach! I'm very glad to be making these, one of the more enjoyable parts of game development for me has been writing blog posts for years, so the fact that I can do it again after a year of not & make videos alongside them is awesome.


Audio
Starting on the games audio was something I had actually intended to be in the last update but I didn't have time to get to. I even created a joke video to spoil that it would be in this update but I forgot to post it lol:




But audio is now in the game for real! The first thing I did was add audio to weapons and not only that but ensure that each gun uses completely unique sounds so that they might be identified by sound alone. This includes both a sound for when the weapon is firing but also one for when it's reloading.

Next, I added sound to pawns which would be a sound for when they're idle, a sound for when they're idle & damaged, and a sound for when they take damage.

And finally, I added sound to UI buttons across the project.

After taking several insults from friends regarding the sounds in their early stages, I slowly got them better & better until where they are now.


Walls:
The first and biggest thing I wanted to do this update was change how walls behaved visually in their entirety.

Taking inspiration from RimWorld & Prison Architect the walls adjust based off of the walls around them:

(Old)


(New)


As you can see, a massive visual improvement that makes walls feel like they have depth.

Because the games visual style was entirely inspired by RimWorld, my first thought was to see if there was any public information on how RimWorld achieved their style. As luck would have it only about 15 minutes into looking I stumbled on a forum post from 2018 with no comments. All it had was a picture of a texture atlas from RimWorld but it was exactly the image I needed to see in order to give me an idea.


https://ludeon.com/forums/index.php?topic=47328.0


For those who don't know, a texture atlas is a method where you store multiple textures on a single image. This is done in games like MineCraft to improve performance.


https://www.reddit.com/r/Minecraft/comments/aa29tm/throw_back_from_2011_for_you_all/


It perfectly displayed the 16 different configurations a wall could have based off of what was around them. So I wrote a system which would split the atlas into individual textures. Once I had done that, I created my own atlas and made each texture have a number representing its position in the atlas (Starting at 0):




Now I just needed to figure out how to write code that would know which of these textures in the atlas a wall should use based off of its surroundings.

And that's when it hit me - I could represent it with 4 digit binary. In the 4 directions around the wall, I could represent each direction as a 1 or 0. 1 if there is a wall there, and 0 if there isn't. Here's an example:



If we look back to the atlas, you can see that a wall like this should be represented by texture position 11. So how do we get this code to equal 11?

Well it's all about ordering.

If we make the top neighbor be the first digit, and go clockwise, that example would give us the binary 1 1 0 1.



So to make it short, the first number represents if there's a wall above us, the second number if there's a wall to the right of us, the third number if there's a wall below us, and the fourth number if there's a wall to the left of us.

So using that system if we read it left-to-right then 1101 becomes 11. And just like that, the game can almost immediately determine which of the wall configurations it should use based off of the walls around it.



Visuals
With this new wall system the first new visuals I worked on were for the concrete wall & wood wall:


I also worked on block textures, such as the grass, sand, dirt, stone, and redid the wood texture to be thicker:


And, I also created a texture atlas for pawns so that I could make so they change which way they're facing based off of the direction they're moving (which they now do):




Gameplay
Walls (and all mod objects for that matter) can now be damaged by setting "HasHealth" to true in the mod file. I've also made so penetrable surfaces (ones which bullets pass through) you can also allow to be damaged by those bullets, even though they're passing through.

With that in place, glass walls are now able to shatter/destroy when shot through:


The shatter effect they create is actually another mod object, a prop called "Glass Shatter". This is because in a mod object you can now add the property "OnDestroy_SpawnModObject" which allows you to configure the object to spawn another one when it's destroyed.

Pawns now also have a very small delay between when they acquire a new target and when they'll start firing. This helped me to accomplish two things:
1) Frame-perfect firing no longer occurs (When they fire the same frame they see an enemy) which makes the pawns feel a little more organic.
2) Helps to avoid stalemates. The delay has a small bit of randomness to it. This is because originally if two enemies at an equal distance with equal equipment started firing on each other, they'd both die simultaneously which felt jarring and resulted in many fights where both combatants were dead and felt like no progression had occurred. This still happens sometimes but more frequently one of the combatants will have a slight edge (by around 0.1 seconds depending) and that's enough to make sure one usually survives.

Although, they still can just end up killing each other, because that's a realistic possibility too:


And finally for gameplay, if a pawn is told to move somewhere and there's a closed door blocking them, instead of having to order the pawn to open it first, they will now automatically path to it & open it themselves:


UI & map editor:
You may have noticed in the combat GIF's that pawns are sporting some new bars. There's now a blue bar which represents the weapons cooldown, a purple bar which represents time left reloading, and a yellow bar which represents how much ammo the pawn has left.

I've also changed in the map editor "World Lighting" to "Environment". Because something I didn't have time to get to this update, but which will likely be in the next, are map effects such as fog, clouds, rain, etc.

You can now also adjust the max players that can play on your map as well as what team each slot gets assigned to. Potentially in the future, I'll make a checkbox that just says "Players can pick their own team" so that maps can be designed that don't force teams. We'll see.

Noteworthy extras:
  • I made so pawns won't try to attack something if it's outside of their weapons range. Before, they would try to attack anything within view.
  • Made so pawns get an exclamation mark above their head when they've acquired a new target
  • Made projectile penetration damage penalty to damage multiplier. Now penetrating a surface could result in *more* damage if you chose to do so. I don't know why you would, maybe some sort of sci-fi game where walls boost the damage to your gun. But it's there now.
  • Modified the voxel engine so that the first redraw of a chunk is done using the fastest algorithm. This makes so chunks can quickly be modified, and then an optimization system can later go to chunks that haven't been changed in a little bit and re-render them using a less GPU intensive but slower algorithm.
Summary
I loved doing the livestream on YouTube Monday, it was some of the most fan interaction I've had which was really great. I hope to do more in the future! Thanks for reading, feel free to leave a comment or some feedback, and I'll see you in the next one!

-Blake Gillman

Extras

>Lines of code written:
18,573 lines / 212 scripts.
(+1,524 lines / +8 scripts since last update)

>"Demo Essentials" checklist:
3~4 cover objects
Breach charge that goes through wood
(Done) Pawns
(Done) Biome Editor
Lobby UI
Squad Customization
(Done) Interactables System
(Done) Health System
(Done) Map Editor
(Done) Ranged Weapons (LMG, SMG, Shotgun, Semi Rifle, Auto Rifle, Pistol)
*Melee Weapons (Knife, Baton)
Map Entry Vehicle / Spawn
Loading Screen
Fog of War System
Main Menu
1 decent map
Player UI
(Done) Most things have some sort of SFX

I've changed Melee Weapons to a maybe since I'm not sure anymore that the game will support melee weapons. I think it will which is why I haven't removed it from the list, but I'm not certain so that's why it's now an asteriks.

Notes & Technical Extras

>Voxel engines redrawing 
Originally the voxel engine decided which algorithm to use based off of how busy the engine was. So it would use the slowest if there was only 1 chunk being redrawn, and the fastest if there were more than 4. But I found that any time the slowest algorithm was used the redrawing would take too long and not look good visually.

The fastest algorithm uses up more vertices so it's slower to render on the GPU. This means the fastest algorithm lets you see the changes more instantly but also means your GPU will have to work harder, which is why it's necessary to also have the slower greedy meshing algorithms. The greedy meshing algorithms are meant to find the minimum number of vertices/triangles necessary to render the chunk. The upside is that then the chunk uses less GPU, but the downside of course is that it takes longer to figure all that out.

So I changed the system so that now whenever a chunk is redrawn from a change (Its blocks have been changed in some way) it uses the fastest algorithm so that those changes can be seen instantly. But then later the engine will re-render any chunks that haven't been changed to use the more GPU friendly algorithms. That way chunks that haven't been touched in a little bit use less GPU, and chunks that have just been changed you can now see those changes faster.

Blog Summary

>Notes used to create this post
Audio:
-Added weapon use/reload audio
-Added pawn idle / idle damaged, and damaged audio
-Added door open/close audio (Specifically, wood door)
-Added UI sounds across the project

Visual:
-Made walls adjust texture based off of the walls next to them
-Made new wall textures (Glass, Concrete, Wood)
-Made new block textures (Grass, Sand, Dirt, Stone)
-Modified wood block texture
-Made pawns adjust sprite based off of the direction they're moving
-Made new pawn atlas's (SWAT & Terrorist)

UI:
-Made so pawns display combat stats (Cooldown, Reload, Ammo)

Gameplay:
-Made so walls (and all mod objects) can be damaged
-Made so penetratable surfaces can be damaged
-Made glass wall able to shatter/destroy & Made so mod objects can be spawned when a mod object is destroyed & Made so mod objects can have no collider
-Made so pawns have a slight & randomized delay before firing when acquiring a new target
-Made so pawns automatically path to doors & have them auto-open

Map Editor:
-Made so you can adjust player slots (Max & Team)
-Renamed "World Lighting" tab to "Environment" for future effects

Other:
-Made voxel engine first redraw of a chunk use the fastest algorithm
-Made projectile penetration damage penalty to damage multiplier
-Made pawns get an exclamation mark above their head when they've acquired a new target
-Made so pawns won't try to attack something if it's outside of their weapons range

EDIT (7/27/21): Corrected the binary portion. 1101 is not 11 unless read left-to-right.

No comments:

Post a Comment