class_name EnemyStateStun extends EnemyState
@export var anim_name : String = "stun"
@export var knockback_speed : float = 200.0
@export var decelerate_speed : float = 10.0
@export_category("AI")
@export var next_state : EnemyState
var _direction : Vector2
var _animation_finished : bool = false
# What happens when we initialize this state?
func init() -> void:
enemy.enemy_damaged.connect( _on_enemy_damaged )
print("Enemy State Stun")
pass
# What happens when the enemy enters this state?
func enter() -> void:
_animation_finished = false
#_direction = enemy.DIR_4[ rand ]
enemy.set_direction( _direction )
enemy.velocity = _direction * -knockback_speed
enemy.animation_player.animation_finished.connect( _on_animation_finished )
enemy.update_animation( anim_name )
print("EnemyStunEnter")
pass
# What happens when the enemy exits this Stat?
func exit() -> void:
pass
# What happens during the _process update in this State?
func process( _delta : float) -> EnemyState:
if _animation_finished == true:
return next_state
enemy.velocity -= enemy.velocity * decelerate_speed * _delta
print("EnemyStunProcess")
return null
# What happens during the _physics_process update in this State?
func physics( _delta : float) -> EnemyState:
return null
# What happens with input events in this State?
func _on_enemy_damaged() -> void:
state_machine.change_state( self )
print("enemy_damaged")
func _on_animation_finished( _a : String ) -> void:
_animation_finished = true
print("EnemyAnimationFinished")
My code works fine but the stun animation isn’t happening, i spent like 3 days trying to find the issue. Its when my player attacks the enemy and the enemy isn’t going into stun animation. The rest of my code works but not the stun code. The stun code prints the “Enemy State Stun”, this tells me that Godot know the stun code is there but not when i attack the enemy.
Make a Slime Enemy (part II) // E10 // Make a 2D Action & Adventure RPG in Godot 4
I’m using Godot 4.5.1 and i need the help because I’m stuck and new to Godot