Problem with piercing bullets not hitting enemies

Hello everybody.
In my game, I have an item that grants piercing bullets, allowing bullets to pierce through enemies instead of deleting on contact.
Something does not seem to be working though. When I want the bullets to drain the enemy’s health, only one bullet can be touching them at a time. If my firerate is too high, I would be shooting millions of piercing bullets at an enemy, but it just won’t die. The damage only counts if no other bullets are touching the enemies.

I need help with this please. How do I make it so that EVERY bullet that hits an enemy it, regardless of how many are currently touching it? I want these bullets to work similarly to how they do in The Binding of Isaac, where every single projectile that hits an enemy damages them. Thanks in advance. :slight_smile:
(Note: Each bullet only hits the enemy ONCE)
Screenshot if it helps (Look under “Test Enemy”):

I’m guessing the problem is that you trigger the condition only once.
Basically what is happening, if the fire rate is too high, at the time the second bullet colliding with the enemy the first bullet is STILL colliding too and so because of the Trigger Once condition, it won’t fire the action to reduce health because the collision need to STOP at least for a single frame before the action going to fire again but if the fire rate is too high, the collision never stop.

A possible work around could be is to use an object variable instead of the Trigger Once condition.
Let say each bullet going to have an object variable called “doDamage” and the default value is 1.
Then, this is what you can do:

Condition:
Bullet is in collision with TestEnemy
Variable “doDamage” of Bullet = 1

Action:
Do - GlobalVariable(Damage) to the variable “TestEnemyHealth” of TestEnemy
Do = 0 to variable “doDamage” of Bullet

This way, the bullet going to damage the enemy only once but every single bullet should cause damage to the enemy.

After, if you want the bullet to be able to cause damage again what you can do is

Condition
Bullet is NOT in collision with TestEnemy

Action
Do = 1 to variable “doDamage” of Bullet

After the bullet can cause damage again, but not to the same enemy, only to a different enemy because as soon the bullet hit an enemy we reduce the enemy health and disable the bullet, and enable it again only after no longer colliding with the enemy.

Also, depends how big the bullet sprite is, you may want to make the collision mask smaller. Probably you don’t need to check collision with the entire bullet sprite but only on the tip of the bullet, this way you can also reduce the time how long a bullet is colliding with the enemy and be able to enable damage for the bullet sooner.

Hope it helps.

Thanks. It kinda works!
Now each individual bullet can hit enemy properly, which is nice, but when I line up several enemies together (With spaces between them), each bullet that hits them seem to drain their health in strange ways with varied outcomes. When I rapidly fire at the enemies and the bullets pierce through them, sometimes the enemy in the way back dies first? Each enemy has 10 health, but sometimes they only take 6 hits to die, and two out of the three lined up die at the same time! I’m guessing what is happening is that whenever a bullet hits an enemy, ALL of the bullets seem to reset their “DoDamage” variables, which allows them to damage the enemies much quicker, which is what I don’t want. How do I fix this?
Screenshots:
DoDamage:


Default Value:
59%20PM

Does anybody know how to do this? Please?

Bump your post after 5hours and again 2h after your last post is a little bit early :wink:

Yeah, I know. I just really need help with this.

It is possible. Depends on what conditions you use and how you use them, GDevelop sometime get confused which instance you are referring to also I was expecting to be not smooth because of the size of the bullet hitbox, when you line up the enemies next to each other, it is also possible there is no chance to enable damage for the bullet again (set doDamage = 1) between two enemies because by the time the bullet stop colliding with the first one, it is already colliding with the second but in case there is a bigger gap between the second and third enemy what you going to see is that the third enemy dies before the second.

This is why I was recommend to set the collision shape (hitbox) of the bullet as small as you can. unfortunately, hitbox editing in GD is awkward but try to come up with something like this (red part is the hitbox):
bullet_hitbox

This way you can reduce the time the bullet is actually colliding with the enemy and increase the chance to enable damage for the bullet again between two enemies.

Regarding GD getting confused which instance we are referring to, as it is depends on which events we are using and when, what I would try is when I enable the damage of the bullet again, I would look for doDamage = 0 first (0 means disabled here) this way, we can be sure we pick the exact bullet we looking for and then inside a sub event, check if the bullet is NOT colliding with the enemy and then set doDamage to 1.

Condition:
Variable “doDamage” of Bullet = 0
SubCondition:
Bullet is NOT colliding with Enemy

Action:
DO = 1 to variable “doDamage” of Bullet

This way you can be certain you pick the right bullet.

But it may still going to fail in case you line up your enemies with no gap between them so the bullet has no chance the enable damage.

An other way you can try to solve this is to use a timer instead of checking collision to enable damage for the bullet but you need to be accurate to make sure once the bullet hit an enemy, it is going to wait long enough before enable damage again to avoid damaging the same enemy again.

Condition:
Variable “doDamage” of bullet = 0
SubCondition:
The timer “enable” of Bullet is > X seconds

Action:
Do = 1 to variable “doDamage” of Bullet.

You need to make sure ‘X’ is just enough to avoid damaging the first enemy twice and to damage the second.
And make sure you reset the timer when the bullet hit the enemy.

1 Like