(Solved) Problem with enemy hiting himself

How do I…

I want the bullets of the game to interact with almost everything. The bullet bounce in walls and can hit the one that shoot it.

What is the expected result

When the player or enemy shoot, the bullet don’t collide with himself. Then after if bounce it can do self damage.

What is the actual result

I have a problem where for some reazon the bullet of an enemy teleport when other enemy shoot and destoy it. Its hard to explain but I’ll insert the project if needed (I think its not that big)

Related screenshots

This is the scenary, I made one that its pretty consistent.

There are 3 tanks. The bottom one is the player. The ones with eyes are enemies. After start. The enemies will start searching and when the player is found, they will start shooting.
In this example, the top left enemy will shoot first, then just as the second enemy will shoot, it will be destroyed.

It will look something like this:

I put some logs to show a little more detail for debugging.
It indicates that the bullet 1 of enemy 1 (top left) in that position
hit enemy0 (top right).

Then the bullet 2 of enemy 0 (top right) hit enemy 1…

Meaybe its pretty confusing, hard to explain, I hope I explain myself good enough.

The segment of code are next

This first part its where the bullets are created

Because all do the same, they are in the same group of Tanks.

Then te second and I think this is where the problem is

The bullet collisions

There are 2 loops because I was debugging and here is where I found that when both bullets are created, they hit the other enemies.

The idea of the IDs, its to prevent the one shooting to hurting himself, and then if the bullet bounce, now it can get the hit.

Project files (optional)

I added the project files just in case.
First check the global variables in CONFIG.debug and set it to true.
Then the scene is GameScene
The project is ready to just replicate the problem, just don’t move the cursor and player; if for some reason, seem like it work you can try reloading again (or move a little the player with wasd) until it do the same thing as the examples.
You can pause with Esc, I do just after the enemy its destroyed just to see de logs.

Thank you for reading.

For someone interested, I ended doing it in other way.
The IDs was a headache, I think is was more of a bug with group of colliders or something.
I throw all the IDs in the trash and made 2 adjustments.

First create auxiliar colliders, one extra for the bullet and one extra for the tanks.
Second when both are created link with their respective parent.
And in the end the collision logic was easy.

Some visualization:

The tank collision in the center is smaller that the normal one I use for walls.
The bullet is in front and have similar size as the normal but with an offset.

So with this when te bullet is shoot, simply ignore the normal collision of the tank; and I manually adjust it to not hit the smaller one.

For the code:
First create the collisions and create the link to the tanks

Then similar with the bullets

And in the collision get their links and do the actions.

If someone is trying something similar, honestly I recommend to try other way, atleast.

Oh and if someone know why I cannot edit the title post…
or help me closing it, please.