Godot Engine v4.3.stable.official.77dcf97d8
I am creating an RPG with combat mechanics and am trying to make a weapon with a cool-down. The trouble is that the gun can shoot more often than should be possible. When I press the left mouse button which is mapped to the shoot mechanic in the project’s input map, I can get two bullets to spawn in close succession and thereafter the gun shoots at regular intervals.
I also have a global autoload timer that acts as the delay timer for the gun.
The code for that is at the bottom
here’s the code:
extends Node2D
@onready var marker_2d: Marker2D = $Marker2D
@onready var prelim_bullet_scene = preload("res://Items/Test Items/Prelim Bullet/Prelim Bullet.tscn")
func _ready() -> void:
GlobalWeaponTimer.timer.wait_time = 0.5
func _process(_delta: float) -> void:
look_at(get_global_mouse_position())
if Input.is_action_pressed("Attack") and GlobalWeaponTimer.can_shoot == true:
GlobalWeaponTimer.can_shoot = false
shoot()
func shoot():
var prelim_bullet = prelim_bullet_scene.instantiate()
get_parent().get_parent().get_parent().add_child(prelim_bullet)
prelim_bullet.global_position = marker_2d.global_position
extends Node2D
@onready var timer: Timer = $Timer
var can_shoot = true
func _on_timer_timeout() -> void:
can_shoot = true
print("Timed")