my issue is when i try to kiil one enemy all enemys die ; player code:
extends KinematicBody2D
var motion = Vector2()
const UP = Vector2(0,-1)
const GRAVITY = 20
const SPEED = 200
const JAMP_HEIGHT = -600
signal hit
var derictions=1
signal deriction
var attack_side=false
var lefted_jamps = 2
func _process(delta):
if $Sprite.flip_h==false:
derictions=1
else:
derictions=-1
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
$Sprite.flip_h = false
$Sprite.play("run")
motion.x = SPEED
elif Input.is_action_pressed("ui_left"):
$Sprite.flip_h = true
$Sprite.play("run")
motion.x = -SPEED
else :
$Sprite.play("idle")
motion.x = 0
motion = move_and_slide(motion,UP)
if is_on_floor():
lefted_jamps=2
else :
$Sprite.play("jump")
if Input.is_action_pressed("ui_attack"):
$Sprite.play("atack")
emit_signal("hit",derictions)
if lefted_jamps>0:
if Input.is_action_just_pressed("ui_up"):
lefted_jamps-=1
motion.y=JAMP_HEIGHT
enemy code :
extends KinematicBody2D
const GRAVITY = 20
const SPEED = 100
const UP = Vector2(0,-1)
var velocity = Vector2()
var direction = 1
var health = 3
var enter_attack=false
var enter_entred = false
var hit_speed = 1000
func _ready():
pass # Replace with function body.
func _process(delta):
velocity.x = SPEED * direction
velocity.y += GRAVITY
$AnimatedSprite.play("walk")
velocity = move_and_slide(velocity,UP)
if enter_entred == false:
if is_on_wall():
direction = direction * -1
if health==0:
queue_free()
if direction == 1 :
$AnimatedSprite.flip_h = false
else :
$AnimatedSprite.flip_h = true
func _on_player_hit(derictions):
if enter_attack==true:
health-=1
velocity.x = hit_speed*derictions
pass # Replace with function body.
func _on_attack_body_shape_entered(body_id, enemy, body_shape, area_shape):
enter_attack=true
pass # Replace with function body.
func _on_entred_body_shape_entered(body_id, enemy, body_shape, area_shape):
enter_entred=true
pass # Replace with function body.
func _on_entred_body_shape_exited(body_id, enemy, body_shape, area_shape):
enter_entred=false
pass # Replace with function body.
func _on_attack_body_shape_exited(body_id, body, body_shape, area_shape):
enter_attack=false
pass # Replace with function body.