#Not detecting enemies

1 messages · Page 1 of 1 (latest)

sterile spire
#

I'm making a tower defense game in which I must make a new instance of a tower to create more towers and the tower attacks without the initiate but after initiating it wont attack so what is happening and how can i fix it

leaden patio
#

You probably just aren't connecting the signal when you instantiate the tower node, could you share your instancing code and your scene tree?

sterile spire
#

taking*

#

this is the code

#

and what tree do you want me to send?

#

@leaden patio

sterile spire
#

@leaden patio

leaden patio
#

angler.tscn

#

And showing how the signal is connected would be good too

sterile spire
#

i dont know how to show how the signal is connected but this is the tree

leaden patio
#

Where do you set placed to true?

sterile spire
#

To show the tower is placed down

#

And for it to stop following the mouse

leaden patio
#

No, like where in the code do you set placed to true?

sterile spire
#

its in the angler tscn btw

#

@leaden patio

#

btw @ me when you reply

leaden patio
#

And this is in the Angler script?

sterile spire
#

Correct

#

Also at me when you reply

#

@leaden patio

leaden patio
#

@sterile spire Ok I'm still not seeing any red flags, what does you attack code look like?

#

Oh and are you seeing 1 and 2 printed?

sterile spire
#

extends Node2D

var placed = true
var Enemies = []
var target

#func range_entered(area):
#if placed == true:
#print("1")
#if area.is_in_group("enemy"):
#print("2")
#Enemies.append(area)

func _process(delta):
if placed == true:
if Enemies != []:
target = Enemies[0]
look_at(target.global_position)
else:
global_position = get_global_mouse_position()

func _input(event):
if event.is_action_pressed("click"):
placed = true

func range_exited(area):
if area.is_in_group("enemy"):
if placed == true:
Enemies.erase(area)

func shoot():
if placed == true:
const BLAST = preload("res://Scenes/angler_bullet.tscn")
var new_blast = BLAST.instantiate()
new_blast.global_position = %Bulb.global_position
new_blast.global_rotation = %Bulb.global_rotation
%Bulb.add_child(new_blast)

func reload():
if placed == true:
if Enemies != []:
shoot()

func _on_area_2d_2_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
if placed == true:
print("1")
if area.is_in_group("enemy"):
print("2")
Enemies.append(area)

#

this is the entirety of the anglers code