i cant be killed if on ground, standing still or moving.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By deezy

i can stand on the enemy and run in to them. but if i jump while colliding, i die.
i tested this out on the enemy with same code and they do die if they touch me. so i dont understand what in my code that’s overwrite the code.

func _process(delta):
if is_dead == false:
	
	if Input.is_action_pressed("ui_right"):
			velocity.x = min(velocity.x+acceleration, max_run_speed)
			if is_attacking == false:
				$AnimatedSprite.play("run")
				$AnimatedSprite.flip_h = false
				if sign($Position2D.position.x) == -1:
					$Position2D.position.x *= -1
	elif Input.is_action_pressed("ui_left"):
			velocity.x = max(velocity.x-acceleration, -max_run_speed)
			if is_attacking == false:
				$AnimatedSprite.play("run")
				$AnimatedSprite.flip_h = true
				if sign($Position2D.position.x) == 1:
					$Position2D.position.x *= -1
	else:
		velocity.x = 0 
		if on_ground == true && is_attacking == false:
			$AnimatedSprite.play("idle")
		
	if Input.is_action_just_pressed("ui_up"):
		#if on_ground == true:
			#velocity.y = jump_speed
			#on_ground = false
			if jump_count < 2:
				jump_count += 1
				velocity.y = jump_speed
				on_ground = false
				
	if Input.is_action_just_pressed("ui_focus_next") && is_attacking == false:
		is_attacking = true
		$AnimatedSprite.play("attack")
		var fireball = FIREBALL.instance()
		if sign($Position2D.position.x) == 1:
			fireball.set_fireball_direction(6)
		else:
			fireball.set_fireball_direction(-6)
		get_parent().add_child(fireball)
		fireball.position = $Position2D.global_position


velocity.y += gravity * delta



velocity = move_and_slide(velocity, Floor)
if is_on_floor():
	on_ground = true
	jump_count = 0
else:
	if is_attacking == false:
		on_ground = false
		if velocity.y >0:
			$AnimatedSprite.play("fall")
		elif velocity.y <0:
			$AnimatedSprite.play("jump")
			
		if get_slide_count() > -1:
			for i in range(get_slide_count()):
				if "enemy" in get_slide_collision(i).collider.name:
					dead()

Your collision check is under an else statement, so you only check for collisions if the player is not on floor.

Adam_S | 2019-09-07 10:53