Here's a video of my problem (notice how the firing rate sometimes changes slightly between shots, at random):
https://youtu.be/WIxQw5KP1ys
On higher fire rates this becomes very noticeable and feels really bad.
(I tried modifying the fire rate to higher and lower values, but the problem still persisted.)
Here is the relevant code:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("left_click"):
shoot(current_gun)
func shoot(gun: Object) -> void:
#shoot bullets and play sound effect
next_shot(gun)
The problem isn't with the shoot() function, because when I removed almost all of its code, nothing changed
func next_shot(gun: Object) -> void:
yield(get_tree().create_timer(gun.fire_rate), "timeout")
gun.can_shoot = true
if gun.is_automatic and Input.is_action_pressed("left_click"):
shoot(gun)
I don't know if the problem is with my code or something else, but I'm really stumped on this issue at the moment.