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():
pass

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

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

func _on_sword_shooting_body_entered(body):
queue_free()

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

func _on_VisibilityNotifier2D_screen_exited():
queue_free()

: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()
           add_child(b)
           canShoot = false
           $Timer.set_wait_time(shotBuffer)
           $Timer.start()
        else:
           pass

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.