Godot Version
4.2.2
Question
So when the player receives damage on the ground the damage animation plays once and it’s great and dandy but if I manage to press jump right before getting hit the damage animation plays twice for some reason!
here’s the video for better understanding of the situation:
my code for the damage:
func _on_damagebox_body_entered(body):
if body.is_in_group("Fist") and was_dead == false:
$thud.play()
damage = true
damage_vector = global_position.direction_to(body.global_position)
func player_damage(delta : float):
if damage == true and fucking_dead == false and was_dead == false:
current_state = State.Damage
$scream.stop()
velocity.x = -damage_vector.x * playa_knockback
func player_animations():
elif current_state == State.Damage:
animated_sprite_2d.play("damage_right")
func _on_animated_sprite_2d_animation_finished():
if animated_sprite_2d.animation == "damage_right":
print('S IT')
damage = false
prescream = false
and a code for the takeoff:
func player_jump(delta: float):
if Input.is_action_just_pressed("jump") and is_on_floor() and animated_sprite_2d.animation != "prescream" and scromt == false and fucking_dead == false and was_dead == false:
takeoff = true
$jump.play()
velocity.y = jump_velocity
current_state = State.Takeoff
#jump height variety:
if Input.is_action_just_released("jump") and velocity.y < 0.0:
velocity.y *= 0.6
func player_falling(delta: float):
if !is_on_floor() and velocity.y > 0 and !raycast_down.is_colliding():
was_in_air = true
velocity.y += gravity * delta * fall_multiplier
current_state = State.Falling
else:
velocity.y += gravity * delta
func player_animations():
elif current_state == State.Falling: #and animated_sprite_2d.animation != "screaming":
animated_sprite_2d.play("falling")
elif current_state == State.Takeoff and takeoff == true:
animated_sprite_2d.play("takeoff")
func _on_animated_sprite_2d_animation_finished():
if animated_sprite_2d.animation == "takeoff":
takeoff = false
I am honestly out of my depth here. Also when I want it to print out in debugger 'S IT when the damage animation ends it only prints it out once, even if the animation is played out twice