Welcome to the forums @Uzvar!
You just need to make a timer of sorts. I generally just use a variable within the script for this. For example, you just need to make a couple minor modifications to your code to have a timer between shots:
extends KinematicBody2D
const SPEED = 300
var move = Vector2()
var GRAVITY = 750
const jump = 500
var FLOOR = Vector2(0, -1)
const BULLET = preload("res://scenes/patron.tscn")
var is_firing = false
var bullet_timer = 0
const BULLET_WAIT_TIME = 1 # time in seconds
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
move.x = SPEED
$AnimatedSprite.flip_h = false
$Position2D.position.x = abs($Position2D.position.x)
if is_on_floor():
$AnimatedSprite.play("run")
elif Input.is_action_pressed("ui_left"):
move.x = -SPEED
$AnimatedSprite.flip_h = true
$Position2D.position.x = abs($Position2D.position.x) * -1
if is_on_floor():
$AnimatedSprite.play("run")
else:
move.x = 0
if is_on_floor():
$AnimatedSprite.play("idle")
if Input.is_action_pressed("ui_up") && is_on_floor():
move.y = -jump
$AnimatedSprite.play("JUMP")
if Input.is_action_just_pressed("ui_accept"):
# Before firing, check if bullet_timer is less than or equal to zero
if (bullet_timer <= 0):
var bullet = BULLET.instance()
bullet.direction = sign($Position2D.position.x)
bullet.position = $Position2D.global_position
get_parent().add_child(bullet)
# Set bullet_timer to BULLET_WAIT_TIME
# so time has to pass before another bullet can be fired.
bullet_timer = BULLET_WAIT_TIME
# If bullet_timer is more than zero, subtract delta from it. This will cause the timer
# to reach zero as time goes by
if (bullet_timer > 0):
bullet_timer -= delta
move.y += (GRAVITY * delta)
move = move_and_slide(move, FLOOR)
There are many other ways to handle time between actions, the method above is just one way. There are likely Godot tutorials that show other (potentially better) ways to handle this.
In the future, it may be best to title your topics so that they inform readers what the topic is about. Without clicking the topic, it is unclear what this thread is asking and people may overlook it because of that.
Also, we don't really want "click bait" topic titles or topic titles that do not relate to the discussion. Not saying this is necessarily the case with this post, but I just wanted to mention it as an FYI.