First Experiments with Godot

I’ve been using Unity for several years now but have wanted to shake it up a little. Over the past couple years I’ve been hearing about some open source alternatives, and Godot is one of the prominent ones making the rounds. I’ve been meaning to play around with it for a while now, but haven’t found the time until now. There’s currently a community game jam going on right now for Godot so I decided to participate with a learning project. I’ve made something very small that can be played online on itch.io here. Now that I’ve made something (albeit very small), I have a better idea of how to work with Godot, so I thought I would give some of my thoughts on it.

A VERY small game

Learning resources are difficult to find

When starting work using any new tool, there are a couple different ways you can approach it. Often, I’ll first try to jump right in and make something. With Godot, I hit a road block right away. There’s a graphical interface that might look similar to something like Unity at first glance, but terminology differs greatly and it requires you to work in a very specific manner. Following this I decided to check some tutorials online, but this posed another road block. I found that tutorials tended to either skip over some of the basics, were for older versions that were hard to follow, or tried to show you something very highly architected and again, difficult to follow. I tried following some of these and downloading some sample projects, but quickly fell off. What actually worked best, was Godot’s own documentation where they show you how to build an extremely bare bones version of Pong. The tutorial is literally one page long, but introduces you to node system, input mapping, asset importing, and script editing. While this was a very basic tutorial, it got me started on making progress with my own simple game without trying to go too in depth on the rest of the features of the engine. At this point, I was able to figure out most problems simply by exploring the Godot docs.

Not all editors are treated equal

One of the nice things about time tested commercial game engines like Unity and UE4 is that they have robust and easy to use scene editors. When you launch Unity, you can very easily move around a scene with the arrow keys and rotate your view with a right click. If you know how to play an fps, you pretty much know how to move in UE4. Godot on the other hand…well, I still don’t really know how the 3D scene viewer works, and the 2D viewer still feels cumbersome to navigate. This brings me to another issue. I do all of my game development right now on a 13″ macbook pro. While I don’t expect full featured game engines to cater to laptop developers, there are some very basic issues that cause me big headaches while developing in Godot that I hope can be remedied in later versions. Mainly, scroll acceleration is all over the place and makes it really difficult to zoom in an out of a scene accurately as well as being difficult to scroll through the inspector or built in code editor. The one caveat I would say to this is thanks to the open source nature of Godot, I could feasibly look into fixing this issue myself or at least participate in the discussion of getting it fixed. One last issue that I never fully understood is that at one point the editor was continually using about 30% of my cpu while in the background, causing my fans to spin up and my battery to drain. There’s an indicator in the top right of the window that shows when the editor is doing a redraw and it was always spinning. I tried hitting some toggles and it seemed to do nothing. Eventually it fixed itself, so I don’t know what exactly caused this. This is just something to keep in mind, since this is a tool still in very active development.

Custom language, the good and the bad

When working with game engines, one of the concerns is how they expect you to make your actual code. Unity uses C#, Unreal uses C++ and a built in visual scripting language. There are engines out there that use these, or python, or ruby, or java, etc. Godot bucks that trend a little bit by using their own scripting language that looks a lot like python, called GDScript. Using GDScript seems fairly easy and more importantly, the api around it feels clean and simple to use. That being said, it still means you have to learn the quirks of a new language, especially if you haven’t used python before(I’ve dabbled in the past). It also means you either use the build in editor, or have to find syntax support for your favorite editor. Luckily, while it has some quirks, I found the built in code editor to be pretty decent. It’s fairly fast and does a great job of autocompletion based on both the api and your scene hierarchy.

Learn from my mistakes

All told, I was able to make something playable in a fairly short amount of time, despite some learning curve problems. Here are a couple things I learned that might be helpful.

If you want to have a button, a simple way to do it is by adding a button node to your scene, then going to the “inspector” at the bottom right and changing it to the “node” tab. From there you can select “pressed” and at the bottom hit “connect”. From here you can select the node with your game logic and connect it. This will automatically make a function in your script that gets called when you press the button.

If you want to actually export your game to either an executable or to a web/mobile version, you have to separately download the “Export Templates” file on the Godot downloads page and install that file by going to the “settings” button in the top right of the Godot editor and clicking “install export templates”. I didn’t realize I had to do this and when you try to export before doing that, it doesn’t tell you that anything is wrong. It will even build files that don’t work. It’s possible that I had an old version of the templates already installed, but I really wish it would have told me. This is a mistake that cost me several hours of trying to figure out why my builds didn’t work

In Summary

So far I’m pretty impressed with Godot. It has some weird quirks and there’s a lot I still don’t know, but when I got into a flow, my turnaround time on added features and edits was very fast. After getting over some hurdles I’ve also found that the flow on some features is pretty slick. I’ve just scratched the surface, but I’d like to spend some more time with it.

Making a Unity il2cpp Android build

I’m currently working on a mobile game with a couple of friends called Sweet Ride. I’m also the only one of us that has an Android phone. Consequently, I’m the one tasked with getting the game to run on Android. We had a build running in the past using the standard Mono scripting backend, but with Unity’s push of its il2cpp tech, I’ve been hoping to move the Android over to it with hopes of improving performance, which I could tell early on was going to be an issue.

sweet-ride-game-icon

Now comes the hard part. There appears to be zero documentation on getting this to work, although it should be fairly straightforward. The simple process of getting the android ndk, which is required for il2cpp, hooked up ended up being a pain and I wanted to just write down the extra steps I needed to work this out.

The first problem is that the Android il2cpp settings require a specific version of the Android ndk. I don’t know why this is, but it caused me a headache at first. When I first tried to set this up a couple months ago, the link from Unity’s settings didn’t actually work, sending me to the wrong build. The problem is that Google doesn’t have an easy search for old builds of the ndk because they just assume you want the latest. When I tried it recently, it did actually go to a valid link. I’m on a mac and the file downloaded should have a name like this: “android-ndk-r10e-darwin-x86_64.bin”.

Download the correct ndk

So I had the file now. Great! But Unity needs to be pointed to an extracted ndk repository. Opening the file in finder just puts it in a different compressed format and the third party compression program I use called “Keka” did the same. The solution to this was to turn to the command line, using the third party p7zip tool. You can download this from sourceforge ::shudder::, or if you’re a Homebrew user, just do a quick “brew install p7zip”. Once you have p7zip installed, you can extract the ndk easily by using the command “7z x android-ndk-r10e-darwin-x86_64.bin” in the directory where you’ve put the file. This will create a new directory called “android-ndk-r10e”. Now you can go back into the Unity preferenced and under “External Tools”, point the ndk to that directory.

Now you can go into your Android player settings and change the scripting backend from Mono2x to IL2CPP and start a build. That’s not to say that the build will work. My first build has resulted in a nonfunctional game, but at least now I can work on figuring that out, instead of working on getting the game to build at all.

Setting the scripting backend
Set IL2CPP in the “Scripting Backend” option in the Android player settings.

Adding broken features and the hacks to fix them

When I first decided to work on getting 2Bix shipped, I decided I needed to be able to contribute something significant to the project besides just submitting it. There were a few things that needed attention, such as testing and analytics, but none of that involved actual coding. One of the things Jill felt was missing from the game was animation and overall visual presentation. After looking at the game, we decided a scrolling background would be a simple, but significant addition to the game. As someone who has held a fascination with shader programming, as well as a poor ability at it, I figured this would be an interesting exercise in some basic implementation of shaders. The final result was a nice effect that keeps your eyes engaged, but not distracted. Getting there had a few hurdles.

One of the benefits of this project was it gave me a chance to dig into the game code and have a basic understanding of how it ran. The base library was a tool called Cocos2D which is a popular open source library used by a lot of iOS games, but one I had never used before. After digging around I found where the static background was being loaded into the levels and was able to edit the image. I looked into basic shader functionality for this version of Cocos, which was a few versions old at this point, and was able to make the background scroll. The problem is that it just scrolled a giant background piece that was never meant to be tiled, which is not what we wanted. After playing around with it a bit, I saw that the very center boxes in this image were actually perfectly square and would be tileable.

When making 2D games like this, it’s often common to have a sprite atlas, which is just putting all of your images into one big image(oversimplifying) so that they take up less space. 2Bix uses one large sprite atlas and all of the individual images are basically defined in a property list that lists the coordinates of each element.

This is the part where serious programmers might want to turn their head away in horror. Now, every game ships with code that you might look at and be mystified that someone ever decided that THIS was the way they wanted to solve a problem and even more mystified that it actually works. I’ve committed my fair share of coding hacks in the past and I was trying to get a long delayed project out as soon as possible. Even though the image that I was running the shader on was coming from this property list, the shader actually gets the raw image, which is the atlas, so I wouldn’t be able to just loop on the whole image. My solution for getting just the portion that I wanted was to manually enter the coordinates and sizes in the shader itself. The result is a lot of magic numbers in my code that would confuse anyone not involved in its creation(anyone who isn’t me).

At this point I had a working background scroller and went on to other tasks, until I noticed something after the game was running for a few minutes without me playing. It turns out that there was a serious problem with degradation over time.

output_E6RudiAfter ten minutes on the same screen, the background would turn into a jumbled mess, running at a slideshow speed, though the rest of the game ran fine. I figured that this was probably an issue with precision in the timer that just counted up indefinitely, then transferred itself to the shader, which has lower precision in its values, causing the data to get mangled.

My first thought was to turn the time information into a fixed precision notation to combat this, but was quickly dissuaded by the complications involved in that. In the end, the simplest solution appeared to be wrapping the time every time the tiles had done a full pass. The problem is that when I tried to do this based on the sizes of the tiles along with the speed that they were supposed to be scrolling, it was hitching. The mathematical solution wasn’t working out. Once again, I decided the easiest path for this one off problem was a one off solution. I handled this simply by hand changing the wrapping value until it was smooth. Again, pretty ugly stuff, but it worked, and that’s all I cared about.

At this point, The background scroller has been in the game for months, tested on multiple devices, and it just works. I would like to emphasize that when working on a project, you should try for a more robust solution, but sometimes it’s the hacks that get a project finished. Then, maybe one day after the game is out, you’ll go back and do it right. Probably not, but if you tell yourself that, you might be more willing to let it go and get your game done.

Starting at the Finish Line

2BixTitle

After finally getting a blog together it took me a while to figure out what would make a good first post. This is meant as a general blog about things I encounter while developing software and games. I’ve been a developer of iOS apps for about three years now, and recently got into Android development, but during all that time I’ve still wanted to work on games. I’ve done little projects here and there, participated in a couple of game jams, played around with new tools, but I haven’t actually created a commercial game of any sort. For the past year and a half, I’ve been working here and there on a game with Jillian Ogle, that we started at a game jam. Due to work commitments, I hadn’t been able to make that much progress on it, but there was also another game called 2Bix that Jill had sitting, basically complete, just waiting for finishing touches to get it out for the iPad. As my last job was starting to wind down, I figured it would be good to help her finally get this game out. Now, a few months later, the game has been approved for release on the app store, and we’re just getting together our press material before releasing it. I figure this is as good a point as any to start a blog, with the end of a project.

When I first met Jill at TIGJam in 2013, she showed me 2Bix on her iPad and I played it for a while. It seemed like a polished game that played well on on the device. The game appeared to be close to completion and just needed some final edits. The rest of the weekend was spent on our game, World Eater. After the game jam, we talked it over and decided that we both really liked the World Eater concept and wanted to continue working on it. Unfortunately, I was in the middle of a crunch period at work and had to put off any work for a couple months. Since then, we’ve done some work on World Eater, with some parts going back to the drawing board, and a lot of time off due to other commitments.

IMG_0025

All this time, 2Bix wasn’t really getting any closer to completion. It seemed that Jill had lost some steam on the project, and the original programmers were probably busy with their full time jobs now. Really the game was almost done, but nobody was finishing it up. Jill was already too busy with multiple other projects and paid contract jobs, so 2Bix was just sort of looming over everything. With World Eater in a stage, where we needed to rethink some things, I figured that I could help bring 2Bix to the finish line.

Even though 2Bix was mostly done, there were a few issues that needed addressing. The first issue was a lack of score targets. The problem is that there are a lot of levels, but no easy way to figure out the best scores(lowest number of moves to solve a puzzle). Jill had played through every level and put in her par scores, but she needed at least one more playthrough to verify her targets. At that point I set out to play through every level and attempt to get the best scores I could throughout. This wasn’t a simple task, as some levels are very difficult and have multiple ways to solve them. It actually took me a number of hours to go through and figure out when I wasn’t beating a level optimally. Once I had done a proper playthrough with all of my scores saved, I went through and matched up my scores with Jill’s, and set the proper targets.

The next issue that we wanted to solve, was aesthetics. The problem is that, while the game is very polished, we still wanted it to feel a little more lively. The game had a static interface and minimal effects. It’s also not so simple to spruce things up due to a couple things. First, this is a large code base that I was not familiar with at the time. It was also using an older version of Cocos2D, a popular framework for making iOS games, but something not as simple as Unity, which we’re using for our other projects, to add in new features. After looking at the game and thinking about how we could get the most out of our effort, I decided to experiment with the background. The background was just a static wallpaper, but it was of a tiled pattern. Since the game felt too static, it sounded like a good idea to make the background scroll. I went into the game code and spent a while learning the code base, figuring out where levels are put together, and how assets are being drawn to the screen. After some tinkering, I finally figured out how to replace the background. I wasn’t sure what the best way to make a scrolling background would be, but decided to play around with it as a shader effect.

IMG_0044

Now, I’m not very experienced with shaders, but it’s something I’ve always wanted to spend time with. This was a great chance to work on that skill set. After tinkering with a basic shader for a while, I got the background scrolling, with a number of graphical anomalies. One of the important aspects of this was being able to reuse the existing artwork, even though it wasn’t meant to tile in the way that the shader was tiling. As a result, I had to resort to using a number of magic values to get things lined up just right, and I had to resolve a floating point precision issue that cropped up when you were sitting at one level for too long. I banged my head for a long time trying to figure out how I could properly wrap the time value without losing precision. Eventually, I settled on the most reliable hack I could come up with, which was wrapping the time at point that I had figured out through trial and error. It was ugly, but it worked. Now we had a constantly scrolling background, that complements the game board nicely.

Aside from the two main issues that had been solved, we mostly had to do a lot of bug testing, achievement testing, and dealing with minor compliance issues. Jill also wanted to get some new music into the game. After spending time sealing up all of the issues, it was time to submit. It took a couple weeks, but Apple finally approved the game and now we’re ready to release…sort of.

This is a game that took a lot longer to create than Jill expected, and had been sitting dormant for so long, that we just wanted to get it out at all. We were ready to just send it out and see if anyone played it, but we knew that without at least a little attention to marketing, it was going to be released into a harsh, unforgiving place where it would go unnoticed. Now, who knows if our work will pay off, but we know that the only way it will get any attention is if we put some work into getting the word out. We’ve gone and selected the best screenshots to represent the game, we’ve created a website and a press kit, we’ve even been fortunate enough to get help from 2 Player Productions to shoot a trailer. We’ve slowly started telling people about the game and will hopefully start really getting the word out once we have our trailer and press kit finalized.

IMG_0074

This is a weird project that’s very much an end and a beginning. More than anything, this is representative of us being able to get something out there. There’s no telling if it will do well or not, but we actually did it. This isn’t really my game, but I’m proud to have helped it see the light of day. Once we release this game, we’ll be able to focus again on our other projects and learn from this experience.

This post ended up being a lot longer than I expected(thanks if you’re still reading), but I want to do some more small posts that will hopefully give a little more insight into some of the details I glossed over here.