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.
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
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()
There are a couple of parts to this. First you need a to enable fixed processing
Then in your node settings you need to set Contacts Reported to at least one, and turn on Contact Monitor.
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.
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.
If you want to use the CanvasItem’s _draw() function to draw primitives, make sure you call update() from your process function.