Why do my enemies disappear when the game begins?

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

Hi. I am a beginner to godot and am making a game with it. For some reason, my enemies disappear on game startup despite the fact that I positioned them in the editor. This is my project: GitHub - Code-Ripple/Septicity

Thanks,

the link no exist…

estebanmolca | 2021-08-17 19:19

Sorry, I made the repository public now

Code Ripple | 2021-08-18 09:24

:bust_in_silhouette: Reply From: estebanmolca

I think the problem is that it collides with itself, I don’t know why you put 2 colliders on the tree. Also in the script, in the function function _on_Area2D_body_entered (body): in the last lines you use body.queue_free () and queue_free (), and as it collides with itself it is deleted. I leave comments:

extends KinematicBody2D

var motion = Vector2()

var Health = 100

var bullet = preload("res://Art/Bullet.png")
var explosion = load("res://Particles.tscn").instance()
var bulletSpeed = 1000
func _ready():
	print_tree_pretty()
func _process(delta):
	if Health <= 0:
		queue_free() 
	#print(position)

func _physics_process(delta):
	var world = get_parent()
	var Player = world.get_node("Player")


	position += (Player.position - position)/40
		
	move_and_collide(motion)
	


func _on_Area2D_body_entered(body):

		
	Health -= 20
	print(Health)
	#body.queue_free() # D E L E T E 
	#queue_free() # D E L E T E

┖╴Enemy2
┠╴Sprite
┠╴CollisionShape2D # DELETE THIS
┠╴Area2D
┃ ┖╴CollisionShape2D
┖╴Timer

Thank you! I fixed it by adding an if statement to check that it is not itself colliding.

Code Ripple | 2021-08-18 10:58