Topic was automatically imported from the old Question2Answer platform.
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
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.