|Attention||Topic was automatically imported from the old Question2Answer platform.|
|Old Version||Published before Godot 3 was released.|
Hey guys, I got two things on the scene: KinematicBody2D as a player and RigidBody2D as an enemy. Whenever player touches an enemy he should disappear and then appear in the beginning of the current level. I got this function in character’s script:
func hit(): var PLAYER_SCENE = load("res://Assets/prefabs/dynamic/player.tscn") queue_free() var player = PLAYER_SCENE.instance() player.set_pos(Vector2(0,0)) get_tree().get_root().add_child(player)
And it just loads scene with character, frees current character object and instantiates new character object in (0;0) position.
And enemy got this script:
get_node(“Area2D”).connect(“body_enter”, self, “_collision”)
if (body.get_name() == “Player”):
And it checks whether enemy collides with player and if so, calls hit function which I described before.
So the thing is that it works first two times. After my character dies second time and appears in the beginning of the level it stops reacting on colliding with enemy object and doesn’t disappear, why is that?