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

Help with collision!

André Luiz

Member
I would like my enemy to have a small cooldown before doing damage again, how do I do this?,
Alarm countdown (Create)


alarm[1] = room_speed * 2;

This is my failed code(Collision):

if !alarm[1] {
global.life -=20
}
 

chamaeleon

Member
Please clarify if you want the damage to happen immediately and then no damage will be dealt for some amount of time, or if some amount time should pass, and then damage should be dealt. Your first sentence indicates the former, while your code attempts to implement the latter. If you want damage to happen right away, apply damage and set a variable in the appropriate instance that damage has been dealt, then reset this variable in the alarm event. For the most part you shouldn't have to explicitly check the alarm counter value, just rely on the triggering of the alarm event code instead.
 

FrostyCat

Redemption Seeker
This is very elementary code that a normal platformer or shooting game tutorial would have covered. You should work on your basics.

Create:
GML:
can_hit = true;
Alarm 1:
GML:
can_hit = true;
Collision:
GML:
if (can_hit) {
    global.life -= 20;
    can_hit = false;
    alarm[1] = room_speed*2;
}
 

Joe Ellis

Member
Yeah I use "hurt" as the variable where they can't get hurt if they're already hurt (and flashing). I do have the can_hit\can_be_hurt as a separate variable aswell cus while they're doing some attack moves they can't be hurt, but aren't hurt, as that's the variable that makes them flash.
For the cooldown I don't use alarms, I simply decrease the value of hurt a certain amount per frame, so say if you wanted hurt to last for half a second, you would decrease the value by 1 / 30 each step, (assuming the game is 60 fps) Then ask if hurt <= 0.

You can do the same thing with alarms but I feel like it's adding extra things that make it more complicated, I like just dealing with all of it in code without having to remember different events that're involved
 
Top