Shooting Rockets/explosions issues

Hey! So I’m making a rocket launcher type gun and have run into an issue. At the start of the game loop your firerate is fairly slow and your projectiles starts at 1. The gun feels and works as intended but eventually as you get more upgrades and the firerate increases the enemies don’t take/receive any damage. I’m fairly certain it’s happening when you hold the left mouse down the entire time?

I’m probably doing something wacky in the code, or missing something. Also, I really struggled to get 2 explosions to deal damage (both on one target, when you get a projectile upgrade), I’m just curious if there’s anything redundant or not needed in the code! Help is greatly appreciated :slight_smile:

Shooting bigbullet code:

Hit By bigbullet code:

Hit By explosion code:

Firstly, in your hit by explosions events, you want to iterate for each enemy, not for each explosion. You are updating the enemies, so it makes no sense to iterate over explosions (to which there appears to be no reference in the actions either).

Ignore the above paragraph - as @Keith_1357 pointed out in the next post, I missed the iteration over all the enemies.

Secondly, I think the problem is that you have a trigger once on the ragelevel checks in the hit by explosion code. It’ll action for the first enemy, but not again for any other explosion & enemy collision until ragelevel changes. The condition just checks the value of ragelevel. If it’s not different from the last time it was checked, then it returns false. It doesn’t care about the other conditions or objects being iterated over.

I’m guessing you want the explosion to deal damage once for each enemy, rather than multiple times when enemy & explosion are colliding.

Here’s a solution to that problem. You can replace NPO with enemies. At the time, I used an object string variable, but you can also make it a boolean.

There is a for each enemies then a collision check and then for each explosion. That seems ok. Right?

Trigger once inside of for…each events cause problems. It’s already doing the events just once for each object. Try removing the Trigger once conditions which are inside for…each events (basically inside any type of loop. If it really only needs to happen once, you can set a variable in the loop and check its state,)

To make it easier to write, read and maintain your code, you have 2 events that look almost identical except for the damage. You can have separate lines for the damage event and then for the common events, you can use an OR condition. Unless there’s only 2 possible values then the other event(s) wouldn’t even need any conditions.

Ah, I missed that. Ignore my bit about iterating over the enemy objects (I’ve updated the post accordingly).


But my link to the solution still stands . This

will still apply damage every frame that the enemy and explosion collide, rather than once for the collision. It will apply it only once per frame, but for repeated frames while there is a collision.

1 Like

Yes, unless the purpose of this example was to do something anytime a car was facing a certain direction. :wink:

This was just an example of using a variable instead of trigger once. It would still need other conditions to limit it’s triggering.

1 Like

Yes, exactly right. I want the explosion to deal damage once for each enemy, rather than multiple times when the 2 are colliding.

I followed your NPO example, and removed the triggers once. Now I can fire once at an enemy doing damage and then next shot nothing. If I hit another enemy I can go back and hit the previous enemy dealing damage. Might be doing something wrong with the booleans?

Found my mistake! Just need to swap the explosion’s is in collision with enemies to enemies is in collision with explosions!

Tested a run and so far it’s working great :slight_smile: thank you so much!

1 Like