0 votes

Hello there,
I'm hitting a block with some arrays; I'd like you help :)

I'm making "bouncing" attack system.
function is findtargetbouncing()
my Projective has an area2d that uses getoverlappingbodies when hitting an enemy.
So that I can see if/how many enemies are in range for bounce doing a FOR that breaks once it found a proper target.

Then, I select the closest one, and move toward him. Adding him to the bouncinghistory array.
On hitting the target, the function is called again.
When I'm hitting my "max
bounce" amount, i queue_free() the projectile.

The problem is when there are 2 enemies. and im supposed to bounce 4 times.
After hitting the 2nd enemy, the projectile will wonder chaotically.

So. My (i think) solution, would be to check the array units = getoverlappingbodies
and compare it to the bouncinghistory and that when ALL unit in units are in bouncing_history , I know that my projectile has hit all it could and i can queuefree early.

I just cant figure out a clean way to compare all entries' from an array to an other one.
could anyone illuminate me with this ?
thank you

in Engine by (184 points)

1 Answer

0 votes

Looks to be you are over complicating this issue but answer directly since unsure of your projects set-up

Solution 1

func compare_all_entries(array, other_array)
    for entry in array:
        if not other_array.has(entry):
            return false
    return true

Solution 2

When adding to the bouncing_history if current_bounce is one less than max_bounce queue_free()

Honestly you really should use the body_entered & body_exited signals in lieu of get_overlapping_bodies

by (6,876 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.