Getting Started Gotchas in Godot Engine

Here are some of the things that weren’t clear in the documentation, or were not shown well in the example code, when I first started using godot.

Input parsing

The platformer example code uses a boolean switch to check whether the player is currently shooting and toggle the state at the end of the update function. This is pretty confusing, and would only get worse the more actions are available. A much better way is to respond to events when they happen. To enable this, in your node’s _ready function call

set_process_input(true)

You’ll need an  _input(event) function to handle the events. There’s a bit of a trick to handling a single keypress. You’ll need to check the name of the event against your input map, make sure it’s pressed rather than released, and make sure it’s not the result of a key being held down

func _input(event):
    if (event.is_action(get_action('shoot')) 
        and not event.is_echo() 
        and event.is_pressed()):
        shoot_bullet()

Enabling collisions

There are a couple of parts to this. First you need a to enable fixed processing

set_fixed_processing(true)

Then in your node settings you need to set Contacts Reported to at least one, and turn on Contact Monitor.

collision-node-settings

Next, hook up the _on_body_entered event

connect("body_enter", self, "_on_body_enter")

Now you’ll be notified when your object hits something, and be passed a reference to it in the handler function.

 Explosive particles

This is a bit of an edge-case, but I’ll mention it becuase I got stuck on it for a while. If you want an explosive particle system, and you’d like it to respond to some event, you have to set Explosiveness to a very small, non-zero value. If you set it to zero, the particle system seems to wait for the particle’s lifetime before displaying it.

Debug drawing

If you want to use the CanvasItem’s _draw() function to draw primitives, make sure you call update() from your process function.

Getting Started Gotchas in Godot Engine

Gravitational Combat in Godot

Recently, I’ve been wanting to make a wee uncomplicated action game. I’m trying to use open source as much as possible lately after learning how to use Blender and being blown away by how much it’s capable of. The Godot Engine is an open source game engine for making 2D and 3D games with the all-in-one approach of something like Unity.

godotlogo

It’s fully component-based. The ship is a scene which consists of nodes. The root node might be a static body which tells the physics engine to be interested in it. Hanging off that is a sprite node which contains the texture and a collision shape node which defines the extents of the object to the physics engine.

The space level itself is a scene, and contains instances of the ship scenes and the planet scenes. You can export variables, which shop up in the property editor, to customise them. The planets have mass, whereas the ships have a player identifier so the input can be mapped accordingly.

Code is equally modular. Each node can have an associated script, and scripts are weakly bound by searching for the properties of other nodes, either by knowing where they are in the scene hierarchy, or by knowing their group. The planets are in one group, for example, as are the missiles. This can cause things to break if you shuffle your nodes around.

The developers are quite active in their irc channel (#godotengine @freenode) and the people there seem pretty chill and happy to answer questions.

gclogo

The game is based on one me and my brother used to play, a sort of tanks/gorilla/worms style thing in space called Gravitational Combat.

Mine is going to be realtime, whereas the original was turn-based. Here’s a couple of gifs of it in action.

attack

orbit

Godot’s physics engine is handling the inertia, and collisions, but I had to do the planetary gravity bit myself.

Gravitational Combat in Godot