godot 4
i have 2 automatic weapons in my fps game, and when you tap fire it quickly instead of holding down fire, it fires way to quickly, how do i fix?
machine gun code:
extends Node3D
@onready var Weapon_Sprite = $CanvasLayer/Control/WeaponSprite
@onready var Hitscan = $Hitscan.get_children()
var can_fire = true
func _ready():
Weapon_Sprite.play("Idle")
func check_hit():
for ray in Hitscan:
if ray.is_colliding():
if ray.get_collider().is_in_group("Enemy"):
ray.get_collider().take_damage(5)
func _process(delta):
if Input.is_action_pressed("main_fire_weapon") and can_fire:
Fire()
await Weapon_Sprite.animation_finished
can_fire = true
#Weapon_Sprite.play("Idle")
if !Input.is_action_pressed("main_fire_weapon") and Weapon_Sprite.animation_finished:
Weapon_Sprite.play("Idle")
can_fire = true
func Fire():
check_hit()
can_fire = false
$Fire.play()
Weapon_Sprite.play("Fire")
chaingun code:
extends Node3D
@onready var Weapon_Sprite = $CanvasLayer/Control/WeaponSprite
@onready var Hitscan = $Hitscan.get_children()
var can_fire = true
func _ready():
Weapon_Sprite.play("Idle")
func check_hit():
for ray in Hitscan:
if ray.is_colliding():
if ray.get_collider().is_in_group("Enemy"):
ray.get_collider().take_damage(5)
func _process(delta):
if Input.is_action_pressed("main_fire_weapon") and can_fire:
Fire()
await Weapon_Sprite.animation_finished
can_fire = true
#Weapon_Sprite.play("Idle")
if !Input.is_action_pressed("main_fire_weapon") and Weapon_Sprite.animation_finished:
Weapon_Sprite.play("Idle")
can_fire = true
func _on_weapon_sprite_frame_changed():
if Weapon_Sprite.animation == ("Fire"):
if Weapon_Sprite.frame == 1:
Fire()
func Fire():
check_hit()
can_fire = false
$Fire.play()
Weapon_Sprite.play("Fire")