how to make 2d shooting not so over powerd

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

i want to make a delay time or something like that so i cant spam the bullet
this the code im using for the bullet scene:

extends Area2D

const SPEED = 230
var velocity = Vector2()
var direction = 1

func _ready():

func set_sword_shooting_direction(dir):
direction = dir
if dir == -1:
$Sprite.flip_h = true

func _physics_process(delta):
velocity.x = SPEED * delta * direction

func _on_sword_shooting_body_entered(body):

func die():
yield(get_tree().create_timer(1.0), “timeout”)

func _on_VisibilityNotifier2D_screen_exited():

:bust_in_silhouette: Reply From: SnapCracklins

I would put a timer node as a “buffer” between shots.
You could script it like this, in whatever object is firing bullets:

export var shotBuffer = 1 
var canShoot = true
onready var bullet = preload("bulletScenePathHere.tscn")

func input(event):
    if Input.is_action_just_pressed("ui_shoot"):
        if canShoot == true:
           var b = bullet.instance()
           canShoot = false

func on_Timer_timeout():
     canShoot = true

The timer will reset the Boolean and then allow you to shoot again. Since you export the shotBuffer value, you can adjust it until you get the shooting time necessary between shots.