How to make is_action_pressed rate bit slower?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

i want my bullet spawn bit slower, if use is_action_just_pressed i need to press every single bullet, but when i use is_action_pressed , bullet spawn rate/time way to fast, can i control bullet spawn rate/time?
if yes, can i know how?
thanks and sorry my broken eng

if Input.is_action_pressed("Lclicked"):
	emit_signal("create_bullet",bullet_scene,global_position)

Couldn’t you just add a short timer after every bullet fired?

	yield(get_tree().create_timer( float for time in seconds ), "timeout")

I’ve used this a couple of times myself, not sure if it plays nice with your particular setup though.

vivavovuve | 2020-01-02 12:29

thanks for the idea, i will try it.

potatobanana | 2020-01-02 12:47

:bust_in_silhouette: Reply From: potatobanana

here the answer i get form discord

var reload_time = 0
func _process(delta: float) → void:

reload_time -= delta
if Input.is_action_pressed("Lclicked") and reload_time < 0:
	reload_time = 0.5
	emit_signal("create_bullet",bullet_scene,global_position)
:bust_in_silhouette: Reply From: supper_raptor

Its very simple .

var fire_rate : float = 10 #Fire rate 10 bullets per second
onready var update_delta : float = 1 / fire_rate
var current_time : float = 0

func _process(delta):
    current_time += delta
    if (current_time < update_delta):
	    return
    

    if Input.is_action_pressed("any key"):
       current_time = 0
       #fire weapon