- Edited
im making a wolfenstein 3d clone, and im using a delta counter for fire delay (the games fps and animations fps is at the same value of 35) of the fully automatic weapon, and the weapon uses a animatedsprite2d:
the issue that im having is that when the fire animation is set to loop, after releasing fire it will replay the animation for a frame instead of immediately playing idle like whats supposed to happen:
and if the fire animation is not set to loop it will do this:
code:
extends Node3D
@onready var Weapon_Sprite = $CanvasLayer/Control/WeaponSprite
@onready var Hitscan = $Hitscan.get_children()
#animation fps and game fps at same value of 35fps
#weapon firing animation has 2 frames, each lasting 3 frames
#weapon cooldown delta counter vars
var can_fire = true
var fire_rate = 6
var fire_timer = fire_rate
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):
#weapon cooldown delta counter
#if cannot fire, then
if can_fire == false:
#if timer above 0, subtract timer by one each frame
if fire_timer > 0:
fire_timer -= 1
#if timer is 0, set timer to fire rate and you can fire again
if fire_timer == 0:
fire_timer = fire_rate
can_fire = true
if not Input.is_action_pressed("main_fire_weapon"):
Weapon_Sprite.play("Idle")
#if holding fire and can fire, fire
if Input.is_action_pressed("main_fire_weapon") and can_fire:
Fire()
#if not holding fire and cannot fire, play idle
#if not Input.is_action_pressed("main_fire_weapon") and can_fire:
#Weapon_Sprite.play("Idle")
func Fire():
Weapon_Sprite.play("Fire")
can_fire = false
check_hit()
#audio player
$Fire.play()