0 votes

Hi, nice to meet you guys, Im John (44yo) I have been learning about Godot, I love it. I have been reading the documentation; I think that what I want (add a 'death' animation for Dodge the Creeps tutorial) will be forward after I have understanding of the GDScript language, I already made the game according to the tutorial and added some details on my own, but I can't continue with the next docs until I manage to add that animation (personal issue), because I don't want the player to simply disappear when it is hit. If I move on I will keep thinking on that death animation and dont concentrate in tne next topics, just need that to move on.

The line I have is $Spriteplayer.animation = "dead", player have his own custom sprite for that but is the code that I dont know how or where to put it. Does it go in the player script? below 'func _onPlayerbodyentered(_body):? instead of hide() ofcourse... doesnt work, need create a var? or create a func first?

Please help, I realy want to continue the learning and move on with the next documentations, but Im stuck with this for days

Godot version 3.3.4
in Engine by (28 points)
edited by

5 Answers

0 votes

The animation should be in the _on_Player_body_entered() function. It should be played before hide(). But the collision shape for the player should be disabled while the animation is playing, so that there isn't any other things happening to the player (which could look messy). The code could look like the following (I haven't tested it, BTW):

func _on_Player_body_entered(_body):
    $CollisionShape2D.set_deferred("disabled", true)
    yield($Sprite_player, "animation_finished")
by (3,144 points)

Thanks for your answer

I had thrown that together quickly. The $Sprite_player.play("death") part should be changed to whatever animates the "death" animation on the player. Also, I don't know the code that's triggered with the "hit" signal.

I've tryed with

$Sprite_player.animation = "death" (original line for movements, right, left, etc, animation works fine if I sustitute the "walk" or the "up" anim.)
and a large list of possibles combinations calling that "death" animation, but doesnt work in your code :(

and now... yours
player, "animation_finished") doesnt work either, with the news that player sprite at least does not disappear immediately.

About the "hit" signal, the only thing I know is that triggered itself when
body_entered (mobs collitions) colide with player, just did like the tutorial says.

0 votes

Thanks @Ertain

What happens with the code that you have given me very kindly, and the logical and understandable explanation is that the player continues to show its original movement animation (it does not call the death animation even when it clearly says $Sprite_player.play ("death")), instead if I do not move the character, it remains there on the screen without disappearing (appear too play button, game title, etc), when moving it towards any direction it makes its characteristic walking animation and then disappears (hide ()), not the death anim.

The player already consists of all 3 sprites (death, up and walk)

Any idea?

by (28 points)
edited by
0 votes

Sorry to bother, but does anyone have any idea what might be going on? why with the command that was given me the death animation does not appear but the movement one by default? it's wrong?
Is that the correct way to call the additional death animation? What others could they be for me to try?

by (28 points)
0 votes

I GOT IT! I leave it here in case someone else wants to go a little beyond the tutorial

1- Firts, create a variable at startup and declare it false

var is_dead = false

2.- Declare it at the beginning of func process(delta): as a false condition, so that it is alive and can move (and move the rest of the _process → to be inside of "if isdead == false"

func process(delta):
....... if is dead == false:
.............. var velocity = Vector2()
.............. if Input.is
.............. velocity.x += 1
etc etc... etc...

3.- Add this lines at func onPlayerbodyentered(_body): that specifies what to do when the players dies:

func onPlayerbodyentered(body):
....... var velocity = Vector2() #to call states of movements #NEW
....... is
dead = true #to declare that... is not live... duh #NEW
....... velocity = Vector2(0, 0) #to make him stop #NEW

....... $CollisionShape2D.setdeferred("disabled", true)
....... emit
....... $AnimatedSprite.play("death") #to play your animated sprite for death for the player #NEW
....... yield($AnimatedSprite, "animation_finished") #to hold the next "hide" until the death animation is finished #NEW

....... hide()

4.- Make him life again at the beginning of the function start:

func start(pos):

....... is_dead = false #New
....... position = pos
....... show()
....... $CollisionShape2D.disabled = false

by (28 points)

Glad that you solved it.

0 votes
by (28 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.