I'd be more likely to use
_unhandled_input rather than
if Input.is_action_pressed in some
_process function, since I think
is_action_pressed returns true every time you ask as long as the button is being held down (instead of just once when it is initially pressed).
yield is also not the way to go here; that setup will return once for every time you call yield (!) once it finally times out. That could mean a lot more lasers than you intend :D
I'm thinking of something like this:
$ChargeTime.connect("timeout", self, "beam_fire")
if event.is_action_pressed('charge') and $ChargeTime.is_stopped():
elif event.is_action_pressed('charge') and $ChargeTime.paused:
$ChargeTime.paused = false
$ChargeTime.paused = true
Here's the docs for Input Events that explains
_unhandled_input and its alternatives.
(ignore this, see edit)
While I was writing this, I realized that the godot Timer actually resets every time you call start, so the above code won't let the player incrementally charge up :(
You can still achieve that functionality by adding a variable that keeps track of how much time remains and updating the timer with a new wait_time every time you start it, but at that rate it's probably better to just ditch the Timer and keep track yourself with the delta from
EDIT: Whoops, I'm a fool. Timer has a
paused field that you can totally use to pause and resume the timer. Updated the code above.