Good time to introduce _is_action_just_pressed and *_released

I did the following:

if Input.is_action_pressed("boost"):
	apply_central_force(basis.y * delta * thrust)

if Input.is_action_just_pressed("boost"):

if Input.is_action_just_released("boost"):

And as rhirne12 mentioned, add the thrust_audio.stop() to crash_sequence() and complete_level().

My rationale for this is by using the if/then statements, you’re actively setting variables every frame. By using the other input methods, you’re only doing something when necessary. While it doesn’t make a bit of difference for a tiny game like this, it can make a huge difference in something far more complex. I think it would be a good idea to teach best practices from the start, even if it makes a lesson longer by saying, “you could do it this way, but here’s why you may want to do it this other way instead.”

I think you are right. I paused at the beginning an tried to implement it myself.
I used the is_action_just_released in my attempt.
An else statement stops the audio all the time when one time is enough. But I am not sure what needs more performance: checking an if statement or stopping an audio.

I like this “just_pressed” implementation a lot more. It does introduce a bug, though, where if the boost is held before the scene reload, on scene reload the rocket will start moving without the rocket sound. To fix this, simply do the following:

func _ready() -> void:

Privacy & Terms