+1 vote

That's, my problem. I'm trying to create a shmup in Godot, so for my bullet scene, I added an area_entered() signal pointing to a function that...

1) Checks if the body which collided with the bullet is an enemy, so it explodes.
2) Self queue frees the bullet.

Problem is that if two enemies are at same position and bullet reaches them, both are destroyed, when the "right" behavior in a classic shmup would be that only one would explode. Is there a way to deactivate the bullet detection as soon as it reaches the first collision it detects?

Thanks in advance! :)

enter image description here

in Engine by (109 points)

2 Answers

0 votes
Best answer

Hey Leandro,

I think those detection (and the emitting of the signals) are all done at once. But you could use the Array returned by get_overlapping_areas() to just delete the first item. This list should not update till the next physics frame, I believe.

Hope it helps. Good luck, your game looks pretty cool.

by (864 points)
selected by

Thanks, Jowan. This is my current function...

Now how to pass the parameter to this "getoverlappingareas()?

func _on_PlayerBasicShot_area_entered(body):
if body.has_method("got_hit"): #if the hit object has the function to explode it, execute it.
    body.got_hit()  #Destroy the enemy ship.
    queue_free() #Remove bullet from main.

So I would just not use the original body variable but instead replace it by the first item in the array like this:

func _on_PlayerBasicShot_area_entered(body):
    body = $AreaName.get_overlapping_areas()[0]
    if body.has_method("got_hit"): 
        body.got_hit()  #Destroy the enemy ship.
        queue_free() #Remove bullet from main.

I'm not quite sure if that gives an error when trying to let it explode a second time. But a test should show :)

0 votes

Silly me... Just added a counter in the scene to check if it was already used and problem solved. Now it detects only the first hit. :)

func _on_PlayerBasicShot_area_entered(body):
#get_overlapping_areas()
if body.has_method("got_hit") and collisions==0:
    collisions=1
    body.got_hit()
    queue_free()
by (109 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.