Ok, I am working on a state machine for an Action RPG enemy. I have three attacks. I want there to be a telegraph state where the player gets an audio warning before the enemy attacks. I have tried using a timer and using a yield both seem to make the attack cooldown wonky. Any suggestions would be appreciated.
This is my telegraph state:
TELEGRAPH:
velocity = lerp(velocity, Vector2.ZERO, 0.1)
var rng_attack = (rng.randi_range(16, 1) * press) - press
var now = OS.get_ticks_msec()
if now >= next_attack_time:
sprite.self_modulate = Color("#2E2EFE")
if rng_attack < 20 && attack1_cooldown.is_ready():
$Sfx/Attack1.play(0.0)
print("attack1"+' ', rng_attack, ' ', press, ' ', attack1_cooldown.time)
which_attack = 1
next_attack_time = now + attack_cooldown_time
state = ATTACK
if rng_attack > 20 && attack2_cooldown.is_ready():
$Sfx/Attack2.play(0.0)
print("attack2"+' ', rng_attack, ' ', press, ' ', attack2_cooldown.time)
which_attack = 2
next_attack_time = now + attack_cooldown_time
state = ATTACK
if rng_attack == 0 && attack3_cooldown.is_ready():
$Sfx/Attack3.play(0.0)
print("attack3"+' ', rng_attack, ' ', press, ' ', attack3_cooldown.time)
which_attack = 3
next_attack_time = now + attack_cooldown_time
state = ATTACK