How I use Rust and Godot to Explore Space

Tom Leys
4 min readSep 18, 2019

--

Each evening after the kids are asleep, I load up some music and decide what I want to work on next. If I’m feeling visual, I load Blender or Substance Painter. If I’m in a “quick progress” or prototyping mood I jump into Godot and if I want to deepen my gameplay it’s time to load up and edit my simulation in Rust using CLion.

Making your own game is all about incremental improvements.

Floor and wall layout with auto-lighting

I’ve been coding for a long time, so I have strong opinions about the quality of my foundations when I’m working on a project. I had to do a lot of self-talk to avoid writing my game directly against a graphics API (the dreaded own engine). A big part of why I settled on Godot was because I can (in theory) easily dive in and rewrite anything that is bothering me, there is an exit hatch. Also, it has a free dark theme. That’s important too!

In case you hadn’t noticed— Unity has a dark theme, but it’s only for paid versions. Those little locks and inconveniences really do add up.

Making a spaceship by drawing boxes

It didn’t always work this well.

Spaceship building needs to be accessible. As demonstrated here your ship is easy to both create and destroy when assaulted with those mysterious blue and red UI elements. The challenge comes in finding the materials to do the building, making the parts inside the ship interesting and functional. I’m looking forward to figuring out exactly how the building animates and how much it costs.

For aspiring developers, I want to remind my readers that the floor and wall building didn’t always work this well. The bugs shown in this little clip are … mostly fixed now.

A quick view into the first Rust function called after you create or delete floor

I prototyped the logic for floor placement in GDScript but decided that I really wanted to be doing this in Rust for performance reasons, and to enable easier unit tests. The way the floor building works now is

  1. UI / Cursor actions and elements are all managed fully in Godot and using GDScript. I’m just using 3D meshes made in Blender and stretching them in code.
  2. Each time the user has decided on an action, this is sent via a method call to my “ship node” which has a GDNative script running in Rust
  3. The action is serialized via serde, sent to the server via cobalt and back again synced to a future tick
  4. When the action is executed locally, it updates a 2d boolean matrix of where floor is allowed to be and creates / updates and deletes wall “modules”
  5. Rust code creates scene instances for each module and places them in the right place — grid XY becomes 3d vec3(x, 0, y) because Godot is a Y up world.
  6. Rust code also tiles the floor and instantiates meshes. I thought about using something called a “multi-mesh” for this but it didn’t support good lighting.
  7. Rust code also creates pretty point lights :D
The best Unit Tests use ASCII Art

You really can do this yourself

If you want to follow in my footsteps, I suggest you start by downloading Godot. There I suggest that you follow the Godot Tutorials and then try to do some simple things in Rust once you know how to do them there.

I have written a guide on creating Gorgeous Godot Games in Rust which you can read to help you get started once you are ready.

It took me about an hour from concept to in-game, with my kids “helping”

If you’ve been an aspiring game developer for a while, you’ve probably got a better foundation in the key knowledge than you think you have. I was surprised to find out how easy it was to begin working with Blender especially once I found some great online resources such as Blender Guru. Here’s a tutorial which includes info on how to get Blender assets into Godot.

From there, it really is a choose your own adventure. I suggest that you become active in the Godot Reddit, Discord or elsewhere where you will find a lot of friendly assistance. Also, indulge your YouTube watching habit with those great tutorial videos. Keep building and you’ll get there!

Please Follow me on Twitter or Chat on Discord and tell me how you go!

📝 Read this story later in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--