I know this has been gone over before on this forum, but this is somewhat related to my last question. I want to improve performance and I’m considering something where each bullet hits each enemy it pierces.
The problem is that it doesn’t register the hit if the enemies are overlapping, or if two bullets hit the same enemy at the same time when Trigger Once is active.
The easy answer is trigger a state of an enemy to indicate it gets hit. But that wouldn’t account for a lot of different types of bullets flying around and hitting different enemies. Does anyone have any experience with this?
I could in theory make it so that it triggers a ‘hit’ state that refreshes after a couple MS, but that’s currently what I have anyways to make it so that the bullets hit multiple enemies at once, and it’s hogging a lot memory.
Are the bullets visible? If they are visible, I think the best option is not to use trigger once and do events that detect collision between the bullet and the enemy and as an action generate damage and destroy the bullet. This will mean that in the same frame that the bullet makes contact with the enemy, it will be eliminated. This still consumes resources, but you could use an initial condition that the bullet is present in the layer to analyze the collision; On the other hand, as a sub-event (so that it can be analyzed only if the bullet is in the layer), as a condition that the bullet is in collision with the enemy.
Another alternative would be that instead of collision detection you use the distance detection of the bullet with respect to the enemy. If the bullet is equal to or less than a certain distance from the enemy, deal damage to the enemy and eliminate the bullet. Keep in mind that if there are many overlapping enemies, perhaps you could use as a condition selecting the enemy closest to the bullet to execute the damage action. If the bullet has slow movement, you can use a timer so that every X number of seconds it detects or collides or distances itself from the enemy.
If the bullet is not visible in the game, you have more alternatives.
Did you try for each event?
Right click any event and choose add then for each object
It should not work in conjunction with for each but can (turns out some stuff works with trigger once in for each loop)
I just don’t know if in for each event you need to select bullet or enemy
But it is either A or B
In link to preview above i placed soldiers and units in a way so both bullets of each soldier goes trough building 1 2 and 3 (and that is not 2 but 4 objects at the same time damaging them thx to for each event)
But trough 4 goes only bullets of one soldier
And you can observe it just by looking at HP bars
HP bar of building 4 is going down 2x slower than HP bars of buildings 1 2 and 3
So i am throwing not 2 but 4 same bullet objects trough each building and they count each (except building 4 which is getting only 2 bullets)
And so each bullet damage building 1 and 2 even so they are overlapping each other so bullets go trough them at the same time where bullets are the same object
Then bullets travel trough building 3 and 4 and they still damage these buildings
Just that building 4 is not getting hit by bullets of one soldier because it is not in their trajectory
So your question does not make sense to me but like i said i think it because you did not understand what you are seeing there
And just to be clear
Red buildings are copies of same object while pink ones are also copies of themselves but are not copies of red ones
I like that concept. I might use it myself sometime. I wouldn’t use the array tools though. I would use either a boolean structure or array. Something like hit(target.Variable(id)) then you could check if collision and variable is false then set to true and do something. You’d probably need a for each bullet and maybe even a for each enemy depending on the actions.
Edit: I don’t like maintaining IDs. I wonder if using linking would be better. I need to do some testing. It would be more automatic and 2-way. So, you could check from either perspective, the bullet or enemy.
The downside is while you could probably set multiple booleans to true with 1 action, I don’t think you can link more than 1 pair of objects at a time.
Edit: As to a solution to this problem. IDK. I would normally delete the bullet with the first hit.