This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 setswordshootingdirection(dir):
direction = dir
if dir == -1:
h = true

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

func onswordshootingbodyentered(body):

func die():
yield(gettree().createtimer(1.0), "timeout")

func onVisibilityNotifier2Dscreenexited():

Godot version latast
in Engine by (12 points)

1 Answer

0 votes

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.

by (562 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.