The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

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.


func _on_Bullet_area_entered(enemy):
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.

in Engine by (25 points)

1 Answer

0 votes

I changed getoverlapingareas() to signals (areaentered, areaexited) but i got the same result.

by (25 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.