A Mixed Bag

Today had some ups and downs. First thing this morning, I made a third attempt at making my camera shake when the player takes damage, but again with no success. 0 for 3. Ugh. I had been having trouble calling my previous camera shake scripts from the correct areas, so I tried a powerful free Unity tool I discovered through a google search called Cinemachine. Right off the bat, as soon as I created a new virtual camera, all but the anchored UI elements of my game went to a black screen. I didn’t take too much time trying to figure out why, before deciding that I needed to move on for now. I had taken enough time trying to get this camera shaking.

I decided to try implementing a health powerup into the game. I didn’t see any health powerup assets provided for us in my GameDev folder, so I took the opportunity to make a custom powerup icon, with a matching glowing blue aura animation. It felt good to be back in my comfort zone (Photoshop) for a short period of time. Upon returning to Unity I hit a snag. When importing my new custom PNGs, I noticed the background transparency was not showing, and it really made the icon look terrible. Being our other assets were pre-made, I didn’t have the needed experience converting a PNG (texture) to a useable sprite. I received some immediate help from one of our Unity/Art Gurus. I was shown that in the inspector when viewing my imported PNGs, I needed to change the texture type from “Default” to “Sprite (2D and UI)”, and apply. Just like that, my health powerup is looking exactly how I had hoped, with a beautifully transparent background. (Thanks for the help!)

The first part of the health powerup implementation was pretty simple. I already had a working powerup script to attach, giving it the same downward moving behavior and spawn rate as the other three previous powerups. All I had to do was add it into my powerup array in the code and update the inspector accordingly. Well, that’s almost all I had to do. Of course I get an error upon collecting my health powerup basically reminding me, “Hey guy! What do I do?!?”
I took some time to look over my player code, especially concerning the damage method, being I want to do just that, only the opposite. So, that’s what I did. I created a “Heal” method, and added a basic line of code to say “_lives = _lives +1” if the powerup is collected. It works like charm, only adding a conditional to keep me from amassing more than the starting three lives. Now I just need to get my new heal ability to play nice with my UI manager.

Demo showing thruster speed, health powerup and camera shake when hit.

After a missed attempt at adjusting my visual player damage elements to update correctly with my new health powerup, I stubbornly returned to the camera shake challenge. This time my perseverance paid off. Some online research told me that when applying my first virtual camera with Cinemachine, that I might need to reposition my Z axis. It’s a 2D camera so it didn’t occur to me to double check the Z! That was the camera view fix. I was zoomed so far out of my scene, that all I saw was the black background. Ok, after getting my new virtual cam into position, it was back to the shaking. I did still need to research and implement a good working shake code for my camera that interacts with the Cinemashake functionality. During this process I noticed something that probably could have fixed my previous fails…making the shake function static so it can be called from anywhere. Cool! I headed back into my damage method, figuring that’s where I want to trigger the shake, and call it with CinemachineShake.Instance.ShakeCamera(5f, 0.1f); save, and play the game praying that the camera finally shakes when the player is it, and it does!

Well, as exciting as that progress was, some of my road blocks reminded me that I do need to get back into the C# survival guide, as that will help me from feeling like I am often trying to ram my way clunkily through these framework challenges. Tomorrow is another day, and I am excited to try and push forward with these new tasks.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jared Amlin

Jared Amlin

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.