I am currently trying to figure out how to tie a timer to the rifle scene in my game. How would I tell the rifle to fire again after the timer has completed?

extends Node3D

@export var bullet : PackedScene
@export var muzzle_speed = 1
@export var millis_between_shots = 100

@onready var rate_of_fire = $Timer

var can_shoot = true

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	shoot()

func shoot():
	if can_shoot:
		var new_bullet = bullet.instantiate()
		new_bullet.global_transform = $Muzzle.global_transform
	#	new_bullet.speed = muzzle_speed
		var scene_root = get_tree().get_root().get_children()[0]
		scene_root.add_child(new_bullet)
		print("pew!")
		can_shoot = false
		rate_of_fire.start()
  • Connect the timer's timeout signal to a method that sets can_shoot to true.

Connect the timer's timeout signal to a method that sets can_shoot to true.

11 days later