Blog

Audio and particle effects

Now that all of the game mechanics are refactored I spent some time getting the audio clips and particle effects back up and running. I didn't like the previous object pooler that I had for the particles, so I replaced it with another one that I made recently. The game looks so much better now! A completely different feel with these small touches. I did also want to put the leaderboard back into Epic Ball as well, but I feel that I need to finish with this project now, so I won't be instituting anything more at this point. Something interesting with the audio clips. Each block plays a short "bump" clip when making contact with something, but that meant that 2 clips would always play when they bumped each other or the player. This caused an unpleasant slight echo, or a slightly louder sound than I wanted. So I just had them check if the OTHER block had already played a sound, and if not, only then to play a sound and set a temporary variable that they had played their sound that frame.





Rigid Bodies

I'm so happy! When I first made Epic Ball I was really limited with the amount of blocks that I put in each level, and also how many blocks I could stack ontop of each other. the main reason being that the rigid bodies on each block were always active. This means that each block runs through its own physics code every frame and takes up a lot of unnecessary CPU power for every block that isn't actively moving. Unity also has an issue with many rigid bodies stacked ontop of each other. They tend to constantly sink into one another very slightly and then readjust. This is mostly unnoticable until you start stacking over 20 or so blocks. At which point they start bouncing a bit and then fall over on their own. But, I finally found a solution to both of these problems with just a few short lines of code! There is a way to put rigid bodies to sleep after they are moving slower than a specified threshold. Once they are asleep, they will wake up again if/when force is applied to them. However, if you have some stacked blocks and knock out the ones underneath, the upper ones won't wake up since no force was applied to them, so they just end up floating in the air.. To resolve this I put a trigger collider on each block that is only slightly larger than the block. Whenever a block exits that collider it will wak up the box with the trigger! I'm happy it was a very simple solution and I'm and that it increases the performance of the game. Theoretically I could now and many more blocks and stack them higher, but I don't think I'll be doing that right now.





Details.. details

Okay, so I've finished refactoring all of the scripts, although there are definietely many more improvements that I can make to Epic Ball. I supose there is no end to that, but I have to draw a line somewhere. Epic Ball is much more efficient now than it was (I actually found and corrected a bug that was causing a coroutine to reinitialize every second o_0), so after fixing these problems I'm much happier with it. I think I'm almost fnished refactoring it now. So I'm play testing Epic Ball many times to catch any other small details that may have been affected by the refactoring. Also, because I really enjoy playing it!





Bugs!

Even after playing every level through I am still finding bugs in the chaser movement (in particular the giant blocks), plane detectors, materials on objects etc. Generally these are bugs that came up only in specific levels because I hadn't built some levels soley out of prefabs that I had made, so sometimes changes that I had made to the prefabs weren't changed on those certain objects. But I do believe that I'm getting to the end of the bug testing period because everything seems to be working smoothly now.





Ugh

Well, now I went and did it... While I was refactoring the ball and cylinder chasing codes I accidentally renamed the fields, which reset ALL of the chasers in the whole game to the default amounts... This means I have to play through each level and find the correct speeds and forces that should be used for all of the chasers. There is a tag [FormerlySerializedAsAttribute] that can be inserted just prior to a field that you want to rename which allows Unity to acknowledge that this is the same field and not something new. So the next time Unity saves the scripts it will keep the relevant information. Then you can remove that tag. Now I know....





Materialize

The blocks were using materials that didn't look var nice, and a few of them didn't have normal maps which made them lookd quite bland. So I really wanted to change them to make them look better. I found a few small jpgs that looked nice but the resolution was vow and the larger blocks looked pixelated. So I used an image upscaler and got the resolution up to 2048 x 2048 which looked a lot better. In order to make the material wrap nicely on the spheres and cylinders I downloaded an AWESOME free program called Materialize, which also can make every other texture you'll need for your objects! So I made normals for the block as well and put the new materials on and I think they look much better.





Saving using Json

O m g... For some reason I never learned that you shouldn't store save game information in scriptable objects because they won't keep the new information input at runtime outside of the editor... So, since I was doing precisely that, I learned how to create Json files and store the save infromation there instead. So basically the scriptable objects are still used to hold the save information at runtime, but it is then immediately stored in a separate Json file so it doesn't matter that the scriptable objects will revert back to their previous information when the game is closed. When the game is reopend the save information is read in the Json files and repopulates the scriptable objects with the saved infromation so that it can be easily accessed by the game scripts.





Building

So, I set all of the appropriate settings in project settings and preferences (there's a lot of them!) and put in the icons for Epic Ball. The Windows build came out great! Very fun to play and now my kids can play it on their computer instead of using my phone, since they don't have a smartphone :P. However, when I tried building it for Android it kept giving me several errors. After many hours of trying to work them out it turns out that I need to turn off each of the Android external tools in 'preferences' and then restart unity and turn them back on and it builds fine... Which is great, but I couldn't find a permanent solution to fix this which is frustrating. Anyway, now I have a complete build of Epic Ball for Wndows and Android :D.