TL;DR: If your player unexpectedly creeps slowly in some direction… check your joystick if you have one!
I bought the Humble Unity Bundle 2019 a while ago (the bundle is long over so don’t bother checking), mostly to get access to the training that is part of the bundle. The course that I am currently doing is The Ultimate Guide to Game Development 2019. It is the same content as this Udemy course as far as I can see, but hosted at GameDevHQ.
As part of the course I am building, step by step, a 2-D galaxy space shooter game using the brilliant assets that are included in the course. The featured image shown at the top of this post is a screenshot of what the game looks like right now.
No software development project, game or otherwise, happens without having to fix interesting bugs along the way. As simple as this game is so far, it is no exception to the rule. This is the second weird and wonderful bug I have ran into. So, I decided to share my journey here in the hope that it will be useful to somebody.
The Creeping “Bug”
I added the visualization for the shield power-up today – the blue glowing bubble around the player in the screenshot. And when I tested that, I noticed something most bizarre. My player was slooooowly creeping lower and lower on the screen.
I disabled the shield animation to no avail. I tweaked all kinds of settings that I have no idea what they actually do. And finally I deleted the shield sprite completely.
But still the ship kept slowly moving down.
So, by that point I was desperate enough to add some debug output. I was pressing no buttons at all, and yet the y-input had a value.
Finally it dawned on me – JOYSTICK! I had moved it out of the way earlier in the day, and clearly it ended up not quite zeroed.
I never contemplated that the game would work with a joystick. The controls have all been keyboard-based so far. But once I realized that of course Unity would support the joystick, it was quick and easy to implement a check for the trigger button too.
Now the game is playable with my joystick!