Day 38- Bug Smashers

Day 38- Bug Smashers

Quote of the Day: Jeremy mocking an ad. Was quite funny.

Music of the Day: Anything, from Thin Lizzy to Ghost. I have started to be able to recognize what band is playing within the first chord or two of a song, even if I rarely hear it. Green day has a very distinctive sound vs. Volbeat for example. God I feel like a music snob.

Bug fixing was the name of the game today. First on the List: Timmy crashing the game. That’s bad. So I set out to fix it. I had an inkling that it was because of all of the physics calculations, especially those with the projectile, but I needed to check and make sure. Thankfully, Unity has a very handy tool called the Profiler, which shows you live stats in depth while running the game. Not only does it show you CPU/RAM/GPU usage, but it breaks down what’s using the most of each of those things for you at any given second. And using the Profiler, I confirmed that it was in fact physics calculations bottle-necking the CPU and causing the game to crash. If I timed when the spikes happened, I was able to tell that it was right as a gummy projectile exploded. Now that I knew what I was looking for, I could start trying to fix it.

So I started going through, putting debug statements in every physics-related mehod until i found the one that was doing what it shouldn’t be. And lo-and-behold:

bad

Wow that’s really tiny. If yo can’t read it it says “Explosion” and was called 4304 times. That happened in the space of 2 frames when it should have happened once. So basically, the shot was just constantly exploding on occasion. To spare you the arduous details of exactly why it was doing that, i will try and describe it very simply: remember how there are 2 projectiles, one for the moving shot and one for the exploding? Well, sometimes, when they’re swapped they hit each other, which means that instead of spawning in 1 exploding shot in place of the moving one, it spawns in… well, 4304. Bad news. Simply tagging the shots as “GummyProjectile” and adding a conditional that the thing that triggers the explosion in fact NOT be a “GummyProjectile” fixed that issue.

Then I made a small fix to the powerups (very rare bug with additive timers. Turns out I was using a very over-complicated solution initially that was screwing with the call. Simpler = better more often than not). Next on the list: Oh wait next on the list is still Timmy. This one was less of a bug and more of a feature overlook. When I first started on Timmy, I was still sort of unfamiliar with scripting in C#, so without even thinking about it I made him function properly for single player only. Obviously, MiniBotz is a multiplayer game, so we can;t have that. Changing him to multiplayer functionality was also super easy, basically I just replaced every reference to a single player to a random value in an Array (basically a stored list) of all the players currently in the scene. So now, if there’s one player he functions exactly the same, but if there’s multiple he randomizes his target every time he uses an ability. Pretty nifty.

Alex had earlier given me instructions for installing and setting up Git on my computer, and with the program(s) now fully downloaded I started the process of getting everything ready for cloud-based versioning (YAY!). While it was setting itself up, I moved over to the master computer and started working on a fix for the powerup spawners. For some reason, after a little while of playtime, powerups would stop spawning altogether. Mind you this had nothing to do with my modularization, it was an old bug that just flew under the radar for a while. This one was also an easy fix. It wasn’t so much an error as a lack of necessary code. Basically, there are two scripts that handle powerup spawning: the manager, which tracks the total number of powerups active and tells the spawners when to spawn a new power up, and the spawner script itself, which does the spawning. The bug was caused by the fact that the manager would tell a spawner to spawn a powerup, then increment that one had spawned (there’s a max of 3 allowed in a level at one time), and the spawner script would try to spawn one. But if one was already there, the spawner script wouldn’t spawn one (it has a conditional to make sure that doesn’t happen), but it didn;t then throw that back over to the manager. So the manager would say “Hey make this” then write down that it had been made, but the spawner itself would say “I can’t” and then not tell the manager that. Eventually the manager thinks there are 3 active powerups even though there are actually none. And it’s as simple as that I-assume-not-very-simple-to-a-non-programmer explanation! I just made the spawner throw the data back over to the manager and all was peachy. And with that I was off to the volleyball game.

If you’ve made it this far, congrats! 3 MiniBotz points to you.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s