i code a simple tower defence game and I have a little problem with collisions.
I wanted to create mechanism that, if the enemy get hit by a bullet of tower, the bullet will be seek to another enemy(changing his direction to next enemy).
But for some reasons, sometimes the method: 'getoverlappingareas()' just doesn't work.
pierce -= 1
var min_dist = 9999
var the_nearest_enemy = null
print("start XXXXXXXXXXXXXXXXXXX start")
for enemy2 in AutoTargetRange.get_overlapping_areas(): # THIS NOT WORKING
var dist = global_position.distance_to(enemy.global_position)
if dist < min_dist and not enemy2.got_hit_by(self):
min_dist = dist
the_nearest_enemy = enemy
print("end XXXXXXXXXXXXXXXXXXX end")
if the_nearest_enemy != null:
How it works in the practise:
As you can see the output shows Enemys(Areas) between "start" and "stop"(always should be 4), but sometimes the enemies arent detect, despite on the video, the bullet collision overlaps with enemies.