Hi,
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.
code:
func _on_Bullet_area_entered(enemy):
enemy.hit(self)
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
print(enemy2)
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:
look_at(the_nearest_enemy.global_position)
How it works in the practise:
https://youtu.be/LXQU9N1Q8oo
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.