Failing to get Hurt

Godot Version

Godot 4.2

Question

I’m trying to make it so that upon touching the enemy, all movement will stop, the player character will play an animation, then the game would restart. The detection and pausing node is a scene in the enemy scene, which is then put in the main scene. So far, the game stops when touching the enemy. However, I’m struggling to make the player character do the animation. I’ve tried using signals, but all the solutions I found were either outdated or not helpful.

…Am I doing this right? I never did a forum question before…

Everything you need to know is in the docs: AnimationPlayer — Godot Engine (stable) documentation in English

If you’re using an AnimationPlayer (you didn’t specify), use play(“animation”) and then is_playing() to check if the animation is finished before doing something else like ending the game. Ideally this animation should not be set to loop so that it will end.

If you are using an AnimationTree, which is more complicated, then you will have to use parameters: Using AnimationTree — Godot Engine (stable) documentation in English

Can I see the code you use for pausing the node?
My guess is that you are also pausing the player node which stops all processing in the player script.

1 Like

That doesn’t happen, I made it so the player is unaffected by the pause. That part is working smoothly. Here’s my script for Pain:

extends Area2D

func _collision(body):
	print("You died sucka")
	get_tree().paused = true
	get_tree().paused = false
	get_tree().reload_current_scene()

I’m having trouble getting the player node to detect the game is paused or getting Pain to send a message. The only time the player and Pain nodes are together is in the Main scene where the Pain is compacted in the Enemy, getting rid of most of the ideas shown in tutorials.
And the only nodes I’m using for animation are the AnimatedSprite2D and CharacterBody2D of the player character.

if you know it only collides with the player then you can call a function on the colliding body, and await a signal on them too

extends Area2D

func _collision(body):
	print("You died sucka")
	get_tree().paused = true

	body.play_death_animation()
	await body.death_animation_finished

	get_tree().paused = false
	get_tree().reload_current_scene()

I DID IT!!! Here’s the new code for Pain:

extends Area2D

@onready var player = $/root/Game/Player

func _collision(_body):
	print("You died sucka")
	get_tree().paused = true
	player.death()

Now, the Pain node calls upon the player’s function. Thank you for your help and patience.

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