Oh, sorry if i seemed impatient.
The thing is, you are doing too many validations with the variable is_alive
that can be a problem.
Here when I asked you to remove the function, it was from inside the if is_alive:
piece.
Something like:
# Apply movement
if is_alive:
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
As you can see, now the move_and_slide function (that is the one responsable for making the player move) will trigger regardless of whether the player is alive or not.
So even if it collide with the slime, trigger the die
function and updates the variable is_alive
to false, the player body will keep moving and not just freeze mid air
The same idea occours here:
if is_alive:
if is_on_floor():
if direction == 0:
$AnimationPlayer.play("idle_right")
if direction > 0:
$AnimationPlayer.play("run_right")
facing_right = true
if direction < 0:
$AnimationPlayer.play("run_right")
facing_right = false
else:
$AnimationPlayer.play("jump")
Where the jump animation (that I believe is the same for falling) won’t trigger unless the player is alive.
You can just move the $AnimationPlayer.play("jump")
line to here:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
$AnimationPlayer.play("jump") # added here
Another thing regarding the multiple if statements using the is_alive
var goes in your last paste bin from line 35 to 64. There are too many validations for this variable that could be done only once, something like:
if is_on_floor():
if is_alive:
if direction == 0:
$AnimationPlayer.play("idle_right")
if direction > 0:
$AnimationPlayer.play("run_right")
facing_right = true
if direction < 0:
$AnimationPlayer.play("run_right")
facing_right = false
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
else:
timer.start()
if not facing_right:
$AnimatedSprite2D.flip_h = true
$AnimationPlayer.play("die_right")
else:
$AnimationPlayer.play("die_right")
move_and_slide()