Hi! I'm trying to create a topdown shooter zombie game. In my World (main) scene, I have created several nodes like "Survivors", "Bullets", and "Enemies" where I would add my zombie scenes as a child of the Enemies node in the ready function. The Zombie scene has a detection radius set to 150 and I want it so that if the player enters this radius, the zombie would start going towards the player and its detection radius would increase to 300. But the problem is, when I spawn some zombies, and I enter the radius of one zombie, all of them would increase their radius to 300 even though I didn't enter the detection radius of the others. This is the code in my world scene:
onready var Zombie = preload("res://Scenes/Zombie.tscn")
func _ready():
randomize()
spawn_zombie(5)
func spawn_zombie(num):
for i in range(num):
var Z = Zombie.instance()
$Enemies.add_child(Z)
Z.global_position = Vector2(rand_range(300, 600), rand_range(300, 600))
And this is my script in my zombie scene: (However I will not include the part where the zombie goes towards the player because I have no problem with that.)
func _physics_process(delta):
has_target(delta)
func has_target(delta):
if target: #target is whoever entered the DetectionRadius
$DetectionRadius/Radius.get_shape().set_radius(300)
else:
$DetectionRadius/Radius.get_shape().set_radius(150)
What I have tried so far is that I made a function called "target_seen" in the zombie scene and I placed the expansion of the radius of DetectionRadius code there only to see the same result. I'm a beginner in Godot and I started learning last 3 weeks and this is my first time asking in the site. Thank you!