![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | dany_pitre |
Hi ! I’m trying to make an enemy spawner.
The enemy is supposed to chase the player if it enters a zone. If i place the enemy directly in my level scene, it works well. But when the enemy if from the spawner, it dosent see the player…
here is the script for my enemy chasing the player:
func _physics_process(delta: float) → void:
if player != null:
move = position.direction_to(player.position) * speed
move_and_collide(move)
func _on_Playerckeck_body_entered(body: Node) → void:
if body != self:
player = body
print(body)
here is my script for the spawn:
extends Node2D
var enemy_preload = load(“res://actors/enemy.tscn”)
func _ready() → void:
spawn()
pass
func spawn():
var enemy = enemy_preload.instance()
get_node(“container”).add_child(enemy)
My spawn is composed of two nodes, one parent node that is “spawner” and a child node that is ‘container’.
thanks a lot !