I cant use dead animation

Godot Version

extends CharacterBody2D

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 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

@warning_ignore(“unused_parameter”)
func _on_area_2d_body_exited(body):
player = null
player_chase = false
func enemy():
pass

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()

func _on_take_damage_cooldown_timeout():
can_take_damage = true
$Take_damage_cooldown.stop()

func death():
if health <= 0:
$AnimatedSprite2D.play(“dead”)
can_take_damage = false
global.mob_alive = false

Question

When my mob died I want to play that “dead” animation. death func working can_take_damage etc working buy I cant play animation

did you set the sprite sheet correctly for the “dead” animation? can you show it?

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”)
1 Like

its worked but animation didnt finish keep going

disable looping
image

change the death() function to this:

func death():
	if not global.mob_alive:
		return
	if health <= 0:
		$AnimatedSprite2D.play(“dead”)
		can_take_damage = false
		global.mob_alive = false
1 Like

its blowing up again

show the whole code again

1 Like

extends CharacterBody2D

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

@warning_ignore(“unused_parameter”)
func _on_area_2d_body_exited(body):
player = null
player_chase = false
func enemy():
pass

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()

func _on_take_damage_cooldown_timeout():
can_take_damage = true
$Take_damage_cooldown.stop()

func death():
if not global.mob_alive:
return
if health <= 0:
$AnimatedSprite2D.play(“dead”)
can_take_damage = false
global.mob_alive = false

from the code, the “dead” animation should not be triggered anymore because of the return
did you disable the looping?

1 Like

how can I diasble it Idk if its opened


it should turn into this color if it’s not looping

1 Like

I didnt even notice that button :slight_smile: thanks man

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.