I have this code where a raycast fires after a timer went off and should start when I press a button but it doesnt start
Heres the code
var fire = Input.is_action_pressed("Fire")
func _process(delta):
if fire:
$"../Timer".start()
func _on_timer_timeout():
shootaudio.play()
dot.set_position(ray.get_collision_point())
print (ray.get_collision_point())
I think you want the Input.is_action_pressed check in the if statement in the process function. As it is now you are setting fire equal to the state of the input at the time the variable is declared and never rechecking it.
Change the bottom portion to:
if Input.is_action_pressed(“Fire”):
$“…/Timer”.start()
It would be better to check in the _input or _unhandled_input function, since if you press down the button for multiple frames, then the timer will keep starting each from you press it down.