+4 votes

i want my bullet spawn bit slower, if use isactionjustpressed i need to press every single bullet, but when i use isaction_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)
in Engine by (419 points)

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.

thanks for the idea, i will try it.

2 Answers

+2 votes
Best answer

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
by (744 points)
selected by
0 votes

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)
by (419 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.