Devlog of Pinball
When I found out that we had to make a physics based game I really really wanted to make a pinball 3D pinball machine. And I’ll be entirely honest, I just wanted to 3D model and texture a pinball machine. Obviously I did not finish the model for this little game (I didn’t really intend to now as I don’t have time for that plus the gameplay) but in the future I’d like to properly finish the pinball machine model and have it be playable for my portfolio because I think that would be real cool.
Up until now all but one of the games I have made have been in Godot and have been 2D. So for this game I wanted it to be 3D and I wanted to use something other than Godot because apparently Godot’s 3D capabilities aren’t that great. So I picked Unity because over my dead body will I code in Unreal Engine. I also wanted to use Unity because I am thinking about using it for my final game at the end of the semester, because I want that to be 3D, and I thought it would be beneficial to, y’know, actually use it before that point. So I went with Unity.
So my decision to make the game in Unity did come with some issues, not that I regret it at all, but because It was my first time making a game in it, it did have its challenges. So I had literally no idea how to do much of anything in Unity, especially logic wise. But I didn’t feel too confused by it because it does have a lot of similarities to other game engines that I have already used. So I thought, at least doing the flippers wouldn't be that hard. (it was very hard. I almost gave up on the game). So I knew I could do it through code. And that probably would be the best way to do it. But if i learnt anything for coding in Godot it is for some stupid reason my brain literally cannot comprehend moving things through code. I know in theory it is not hard. But it really is that hard because I am a dumb dumb sometimes. So I did have a backup idea to animate the flippers flipping and then bind that animation to the button press. I just wasn’t 100% sure if it would/could animate the collider, I assumed it could. I asked my teacher about that, and he did confirm that technically yes I could animate it, but just doing it through code would be the simpler approach. Which yeah I agree. (But my brain was just like “absolutely not”)
So I attempted the coding method. Because I am sure it was technically the more correct approach. I got my flippers to spin violently like propellers. But I couldn’t get them to do the proper flipper thing, to rotate in the one direction then reset when the button wasn't being pressed. I know it probably literally could have taken like 2 lines of code. (probably) but again, for the life of me, I can’t move things in code. My brain just doesn't get it. I’m sure one day I'll figure it out and I will look back and realize how simple it has been all along. But that day is not today.
But I wasn’t going to give up on coding it that easily. So I looked for a tutorial and I found one. Only one. (well that wasn’t 2d or ancient or not really a tutorial). And it was pretty complicated. Like this guy probably over complicated this to the extreme. Like he used hinges and set the positions of the hinges and… I don't really know what was going on. But I followed this tutorial like twice and it just didn’t work. And it was way too complicated for me to even attempt to troubleshoot it. Because again, I don’t even really know how Unity works at this point.
So now I was like screw this I’m animating it. And I did. And being a brilliant programmer who totally knows what they're doing. I was like “holy guacamole this is a state machine.” And I actually kinda know what that is. And this is important because I was out here like just gonna animate the whole flipping motion, which in theory wouldn’t properly work like a real pinball machine because on a real pinball machine when you hold the button down the flipper stays up but I was thinking of doing the full up and down motion in one animation and that would just play when the button was pressed but if it were that way there would be no way to have the flippers stay up when the button is down. But I realized that I could just have an up state and a down state and bind the up state to the button being pressed and the down state to the button not being pressed and it worked. And I was like wow… that was easy… too easy… suspiciously easy… So then I was like great! And I only did it on one flipper and was gonna copy and paste the script basically in another script for the other flipper and just change the names and stuff so it references the stuff for the other flipper and for some stupid reason it wouldn't work for the other flipper which I don't understand why it LITERALLY was identical code… like ????? And this was the 2nd time I debated giving up on this game. But then I just deleted the right flipper that wouldn't work and remade it from scratch and then connected the script and it magically worked… no idea why it wasn't working before. I was literally losing my mind but that's okay it worked now.
Alas, I thought I did it. I thought I outsmarted Unity and got my stupid flippers to flip. And I did… but they wouldn't work properly… like they flipped but they wouldn't always interact with the ball properly. Now I was warned about this, about making sure the collisions animate and I thought I did that because I just thought I had to have like the script and the collider on the same thing and it would work. And it did seem to be moving the collider too just not very accurately and when it did hit the ball the ball didn't really seem to get hit hard enough so I didn’t think this had to do with the collider animating (it did but shh I didn’t know that yet). So I did all kinds of stupid things that I didn't understand to make the collision more accurate/have the ball get hit harder. I changed the Update function to FixedUpdate because that does something apparently. And I also had a special ball script (that the guy in the tutorial did) and the ball had a physics material with bounciness and I think resistance was there. So I thought maybe It had to do with the ball so I changed around some of the settings on the ball material thinking it would make it more reactive to being hit. It didn't really work, like it did a little but not enough.
Now this was a problem. Because I could get the flippers to work and hit the ball but it just didn’t seem to hit the ball hard enough to actually function as a pinball machine properly. Which means that the game wouldn’t work. So this is the point I genuinely was like “If I don't get this to work by X day I’m making a dropper in Godot.” So I gave myself a day to figure this out and get the ball to have more velocity(?) when being hit. I did many things. The main thing I did attempt was, In that useless tutorial it did have one thing that did work well, which was the code for the bumpers that would basically force the ball backwards from the direction it came from. I attached that line of code on the flippers to basically fake force, it did work, but it wasn't accurate because it was faked basically and it would fire the ball backwards even if it barely touched the flipper. But wait…there was a silly little checkbox hiding away in some dropdown menu that said “animate physics” and ohohohoho… It solved everything.
It's always a checkbox.
Again, I'm not really sure what was going on here because it was definitely moving the collision shape with the animation before I checked that box, so I don't know if that box just makes it more accurate or what and just allows the physics engine to take into consideration the force from the movement (that's probably what it is). But it worked and I didn’t need to scrap the game yay!!!!!
So basically it was smooth sailing from here.
The only other thing I did was having the bumpers, which I already knew the 1 line of code for. Those worked no problem. I added the bumper code to the “spring” that launches the ball into the game just as an easy way to solve that issue. I then made it so the bumpers triggered points and added a counter to keep track of the points.
And yeah. I'm very happy I stuck with this and didn’t give up on it.