Hello all,
I am working on my first godot game, and would like the enemies to stop moving when they take damage for around 1 second. I cannot figure out how to do this, so if anyone has any ideas, please help me out!
Here is my enemy movement and damage code:
var speed = 50
var motion = Vector2.ZERO
var player = null
func _physics_process(delta):
motion = Vector2.ZERO
if player:
motion = position.direction_to(player.position) * speed
motion = move_and_slide(motion)
func handle_hit(damage: int):
enemy_health -= damage
if enemy_health <= 0:
Global.score += 1
queue_free()
func _on_Area2D_body_entered(body):
if "Player" in body.name:
player = body
_animated_sprite.play("walk")
else:
pass
func _on_Area2D_body_exited(body):
if "Player" in body.name:
player = null
_animated_sprite.play("idle")
else:
pass
Cheers,
Eli