Hello Godot Forum! Just a quick question today. I am probably missing something obvious, but nonetheless this still isn't working and I don't know why. I was trying to test some multiplayer aspects and I made a duplicate of the original player. This one being the exact copy of the original player, except using a different controller. However, when it is supposed to call the death code, it doesn't reset the health, or the scene. Here is the code down below if anyone can spare some time to help :)
extends KinematicBody2D
var movement = Vector2()
var up = Vector2(0,-1)
var isAttacking = false
var facing_right = true
var dead = false
var hurt = false
var knockback = 300
const GRAVITY = 20
const ACCEL = 11
const MAXFALLSPEED = 250
const MAXSPEED = 130
const JUMPFORCE = 405
const NEWGRAVITY = 10
const MAXGLIDER = 150
func _process(delta):
if dead == false && hurt == false:
movement.y += GRAVITY
if movement.y > MAXFALLSPEED:
movement.y = MAXFALLSPEED
if facing_right == true:
$AnimatedSprite.scale.x = 1
else:
$AnimatedSprite.scale.x = -1
movement.x = clamp (movement.x, -MAXSPEED, MAXSPEED)
if facing_right == true:
get_node("HitBox").set_scale(Vector2(1,1))
elif facing_right == false:
get_node("HitBox").set_scale(Vector2(-1,1))
if Input.is_action_pressed("2Right") &&isAttacking == false:
movement.x += ACCEL
facing_right = true
if is_on_floor() == true:
$AnimatedSprite.play("Move")
elif Input.is_action_pressed("2Left") && isAttacking == false:
facing_right = false
movement.x -= ACCEL
if is_on_floor() == true:
$AnimatedSprite.play("Move")
else:
movement.x = lerp (movement.x, 0, 0.2)
if isAttacking ==false && is_on_floor() == true:
$AnimatedSprite.play("Idle")
if is_on_floor() && isAttacking == false:
if Input.is_action_just_pressed("2Jump"):
movement.y = -JUMPFORCE
if !is_on_floor():
if movement.y < 0 :
$AnimatedSprite.play("Jump")
elif movement.y > 0:
$AnimatedSprite.play("Fall")
if Input.is_action_pressed("2Attack") && is_on_floor() && hurt == false:
$AnimatedSprite.play("Attack")
isAttacking = true
$HitBox/CollisionShape2D.disabled = false
if Input.is_action_pressed("2Glide"):
if is_on_floor() == false:
$AnimatedSprite.play("Glide")
movement.y += NEWGRAVITY
if movement.y >= MAXGLIDER:
movement.y = MAXGLIDER
if Input.is_action_pressed("Restart"):
get_tree().reload_current_scene()
movement = move_and_slide(movement, up * delta )
func _on_AnimatedSprite_animation_finished():
if $AnimatedSprite.animation == "Attack":
$HitBox/CollisionShape2D.disabled = true
isAttacking = false
if $AnimatedSprite.animation == "Dead":
Multi.healthone += Multi.maxhealth
get_tree().reload_current_scene()
if $AnimatedSprite.animation == "Burn":
Multi.healthone += Multi.maxhealth
get_tree().reload_current_scene()
func _on_DeathBox_body_entered(body):
# thank you @cypereality for helping me fix this
if body == self and hurt == false and isAttacking == false:
modulate.a = 0.5
$AnimatedSprite.play("Hurt")
$Slime_Timer.start()
hurt = true
Multi.healthone -= 1
# Again, experimental so take use with caution
if Multi.healthone <=0:
# I changed it to one =
Multi.healthone = 0
$AnimatedSprite.play("Dead")
func _on_Slime_Timer_timeout():
hurt = false
$Slime_Timer2.start()
func _on_Slime_Timer2_timeout():
modulate.a = 1
~~~