I’m trying to make my projectiles pierce enemies based on a variable the player has which is 1 by default called pierce amount and have the pierce variable on the bullet 0 by default increase each time it hits an enemy and delete itself once it reaches the pierce amount, but it works really buggy like occasionally doing double damage, passing through every enemy if they’re too close and sometimes not piercing at all.
The problem is the trigger once It tracks the object and not the instances. It will begin to track the trigger once with the first hit but it won’t reset until all of the instances aren’t in collision. Bullets are usually deleted on impact, so that would create its own trigger once effect.
One way around this is to track collisions. In my example, each enemy object is given an ID. When the bullet collides with the enemy it checks a structure variable in the bullet object to see if that ID exists. Remeber: structures names have to be strings while arrays need to be numbers. In my case I use a number but the number is set as a string. I would normally add a letter before the number like “ID13” but I wanted to keep this minimal and to the point. The value of the structure variable doesn’t matter. It’s the existence of the variable that matters. If it doesn’t exist it changes the count and adds the ID to the bullet’s IDs structure variable.
try me: (enemies are spawned from the top, click the button to shoot)
source: GitHub - doug13579/gdevelop-shoot-thru-objects
The text object has the sticker behavior
tysm for the help I’ve gotten everything down except for the “change the variable IDs(enemy.ID) of bullet: set to 0” which action is that?
They’re’ brackets not parenthesis. IDs[enemy.ID] It’s how you create a structure.
Using IDs[enemy.ID] is a dynamic way of creating or checking a structure.
It really should start with a letter though.
Like IDs[“ID”+enemy.ID] so you could also use IDs.ID1 or IDs[“ID1”] because using a number like IDs.1 is frowned against or might even be invalid in some cases. I apologize for that part. It was sloppy of me.
I guess it would only mean changing one line to be sure the child’s name was something like Ids.ID1 Just the highlighted action, add “ID” +
That way the object variable will look like
and the bullet structure variable would look like this. A list of objects that it has collided with.
edit: I updated the file on GitHub to reflect the change.
Last edit: Just a reminder, With the newer way of using variables, you would need to set up all of the variables so you don’t need the Variable() expression.