func _on_hitbox_enemy_body_entered(body):
if body.has_method(“player”) and global.mob_alive:
mob_inattack_range = true
func _on_hitbox_enemy_body_exited(body):
if body.has_method(“player”) and global.mob_alive:
mob_inattack_range = false
func deal_with_damage():
if mob_inattack_range and global.current_player_attack and can_take_damage:
health = health - 50
print("mob health: ", health)
can_take_damage = false
$Take_damage_cooldown.start()
change the phyics process to this, tell if it works
func _physics_process(delta):
death()
deal_with_damage()
if not global.mob_alive:
return
if player_chase and global.mob_alive:
move_and_slide();
position +=(player.position - position)/speed
$AnimatedSprite2D.play(“walk”)
else:
move_and_slide();
$AnimatedSprite2D.play(“idle”)
var speed = 25
var player_chase = false
var player = null
var health = 100
var mob_inattack_range = false
var can_take_damage =true
@warning_ignore(“unused_parameter”)
func _physics_process(delta):
death()
deal_with_damage()
if not global.mob_alive:
return
if player_chase and global.mob_alive:
move_and_slide();
position +=(player.position - position)/speed
$AnimatedSprite2D.play(“walk”)
else:
move_and_slide();
$AnimatedSprite2D.play(“idle”)
func _on_area_2d_body_entered(body):
player = body
player_chase = true
func _on_hitbox_enemy_body_entered(body):
if body.has_method(“player”) and global.mob_alive:
mob_inattack_range = true
func _on_hitbox_enemy_body_exited(body):
if body.has_method(“player”) and global.mob_alive:
mob_inattack_range = false
func deal_with_damage():
if mob_inattack_range and global.current_player_attack and can_take_damage:
health = health - 50
print("mob health: ", health)
can_take_damage = false
$Take_damage_cooldown.start()