• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Bullet piercing enemies

  • Thread starter Deleted member 30238
  • Start date
D

Deleted member 30238

Guest
How can i make bullet collision with enemies to one-hit without destroying bullet?
My current collision event:
Code:
var dmg = 10;
with (other) {
    hp  -= dmg;
}
instance_destroy;
if i remove "instance_destroy" bullet will hit enemy repeatedly, but i want to bullet pierce enemies
 

kburkhart84

Firehammer Games
The 1st thing that comes to mind to me is to actually handle the collisions on both objects. The bullet can determine whether it should destroy itself or not, while the enemy it collides with determines if it can keep taking hits or not. The code on the enemy would set a variable, maybe a count down for a certain amount of time. Then it would check that variable before actually reacting to the collision. The event would still happen since the bullet is still there, but the reaction doesn't have to happen unless you want it to.

Just FYI, the reason I suggest putting this variable and control on the enemy, not on the bullet, is because that 1 bullet wouldn't collide react to the collision with the next enemy it hits as it penetrates through the 1st enemy if the bullet itself is waiting for the countdown, while the 2nd enemy would contain its own countdown variable.
 
D

Deleted member 30238

Guest
It was easier:

Code:
var _dmg = dmg;
var myID = id;
with (other) {
    if (hitBy != myID) {
        hp -= _dmg;
        if (hp <= 0) instance_destroy();
    }
    hitBy = myID;
}
it stores in enemy instance id of bullet it collides and damage only if it doesn't equal.
 
The posted code can cause extra unwanted damage tho, if 2 bullets hit at the same target at the time they will overwrite the hitBy variable and both will keep damaging the target as long as both are inside it. This might not be a problem if it's the player bullets that has this effect and 2 bullets can never hit the same target at the same time but keep it in mind!

To fix this problem you can have a ds_list and keep track of all the target that the bullet have hit. Just remember to delete the list when the bullet gets destroyed!
 
Top