• 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!

Windows Damage cooldown (invincible for a few secs) for enemies.

Gasil

Member
Hello everybody. I seek your advice.

I'm setting up a meele attack on a top down shooter, an attack I want to be able to hit every enemy that collides with its collision mask.

However, as you guessed, an enemy of 10 hp dies instantly on a meele attack of 1 damage because the collision activates per step (I'm using collision event between object_attack and object_enemy)

So I set up an Invincible = 0; variable, and an alarm to make the enemy flash and invulnerable for a few frames just to stop the collision while the attack animation ends.

It worked well according to what I wanted, until I tried to hit multiple instances of the same obj_enemy; I'm assuming everyone of them becomes invincible after the first hit and I am just able to hit and damage a single enemy even if they are all clustered up. Is there a way to make the game set up an alarm for every instance? Or should I use another approach for this purpouse?

This is the code I have:


Code:
/// @meele attack collision (this is written on the obj_meeleattack, the attack animation, on a collision event with the obj_enemy)

if (cooldownDamage = 0)
{
    with (other)
    {
    hp = hp - damage;
    cooldownDamage = 1;
    obj_enemy.alarm[0] = 60;
   }
}
This is the alarm that's under the obj_enemy alarm 0 event

Code:
cooldownDamage = 0;
Could you help me please sharing any other approch to this purpouse if necessary?

Thank you.
 

Gasil

Member
Why did you put obj_enemy here when you clearly understood that it wasn't needed anywhere else?
I was fiddling with the code to see if I could see changes and understand a bit more. Weirdly enough, if I don't put the obj_enemy behind the alarm, I just can hit 1 enemy during the entire play test. Whereas if I put it there, I can hit a single enemy every 60 steps.

I actually don't quite understand.
 

TheouAegis

Member
Oh I see an issue.

Code:
with (other)
{
  if (cooldownDamage = 0)
  {
   hp = hp - damage;
   cooldownDamage = 1;
   alarm[0] = 60;
   }
}
 

Gasil

Member
Thanks friend, I implemented it and worked fine, however I just stumbled in more problems and decided this was a messy way of doing hitboxes and collisions. Thank you for taking the time.
 

TheouAegis

Member
@Gasil

Another major change that may have been needed - it was subtracting from the enemy's hp the enemy's damage, not the attack's damage.

Code:
with (other)
{
  if (cooldownDamage = 0)
  {
   hp = hp - other.damage;
   cooldownDamage = 1;
   alarm[0] = 60;
   }
}
 
Top