Godot 4.3
Hey, I’m new to Godot (I started a few days ago), and I’m trying to make a simple game based on my little understanding of the 2 tutorials by Brackeys. I got stuck on many things, including this issue, which is to implement a death animation when the health variable reaches zero or less.
At first I wrote this:
if health <= 0:
death()
func death ():
animated_sprite.play("Death")
But the collision body, which won’t fall with player, makes the player stuck mid-air
So I asked ChatGPT, and the code now looks like this:
if health <= 0:
death()
func death ():
$CollisionShape2D.disabled = true
animated_sprite.play("Death")
However, without a collision body, the player falls through the screen so I added another collision body node and the code looks like this:
if health <= 0:
death()
func death ():
$CollisionShape2DA.disabled = true
$CollisionShape2DD.disabled = false
animated_sprite.play("Death")
The player got stuck mid-air again, and I’m not sure what I can do.
I barely know Godot and GDScript.On the first tutorial (by Brackeys), I got stuck at something related to a tile map because my version is newer than the one in the tutorial, so I got frustrated and quit. On the second tutorial I didn’t understand anything after arrays, so I don’t know much about the engine
.
Send some context around the if statement. If you have implemented it in the process function, death()
will be called every frame, which could cause some things to get hanged. However, as you say there are other problems, all the other issues would need to be resolved to say something for sure, send them too
1 Like
The if statement is inside the physics_process() function from the CharacterBody2D movement template. Another problem was trying to send a signal from the main node scene to the CharacterBody2D node scene. The health variable was originally in the main node, and I wanted the main node to send a signal to the CharacterBody2D node when the health variable was less than or equal to 0. However, it didn’t work, and ChatGPT couldn’t fix it, so I just copied the health variable code and pasted it into the CharacterBody2D node, then deleted all the label code.
(And thanks for the help)
As I said, if you implement it in a function called repeatedly, it will hang the sprite. Try adding a variable that is only true when the if
statement block hasn’t been entered already, and set it to true the first time it is entered. As for the signal issue, while it is true that handling the player’s health sometimes is best done in the player node, you could try connecting the signal in case you forgot it, how to do it is provided in the documentation. And what do you mean label code?
Also, I strongly recommend against using chatgpt to solve your problems as it strips away the context in which the solution works which can introduce bugs caused due to the difference in surrounding code. Browse the manual instead.
I figured it out before you wrote this reply; I decided it would be better to just make the player fall off the platform instead of falling on the ground. What I meant by label code is the code that makes a label node in the main scene show the amount of health.
As for ChatGPT, I’m going to try to stay away from it and take a look at the manual.
1 Like