Making an enemy apear by entering an area2d

Godot Version

4.2.1

Question

I want by entering an area2d, an enemy apear, kinda like a jump scare scene and deleting a animated sprite in the process(his eyes are visible so when he apears i want the eyes animation to disapear) but I have no idea what the code would look like.

use instantiate() to spawn an enemy scene and disable visibility for the eye sprite

1 Like

yeah im new to godot and dont know the codes… can u tell me what to write?

I don’t know what you have, or how you structure your node and scene

ok I got how to spawn the enemy, but how do I give it the cordinates and position I want?

func _ready():
	var instense=monster.instantiate()
	add_child(instense)

Just use
instense.position = Vector2(?,?)
or
instense.global_position = Vector2(?,?)
depending on whether you want it to to be positioned relative to it’s parent or absolute in the scene.

does it matter if i add it after add_child or before it?

Preferably you’d add this after add_child, cause .position is relative to the parent.

1 Like