GML 1 hit kill

B

Bengs

Guest
Hello everybody i created a attack system but whenever i hit a enemy or the other way arround it is a one hit kill even though my set dmg isnt equal to its health (in my creation code the Cdmg = 0 and Ehp is set to 100 in my enemies create script)

My attack code is :
Code:
        else if ((attack = 1))
        {
            hsp = 1;
            x = x - hsp;
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Left;
            if (place_meeting(x-1,y,par_enemy)){
                Cdmg = 25;
            }
           
            if (image_index > image_number - 1){
            attack = 0;
            Cdmg=0;
            }
My collission code is
Code:
with other{
Ehp -= Obj_Character.Cdmg
}
 

JeffJ

Member
The attack is colliding constantly, thereby sutracting 25 health 30 or 60 (depending on your room speed) times every second.

Simply remove the colliding instance with instance_destroy() after impact and damage subtraction has been dealt.
 
B

Bengs

Guest
The attack is colliding constantly, thereby sutracting 25 health 30 or 60 (depending on your room speed) times every second.

Simply remove the colliding instance with instance_destroy() after impact and damage subtraction has been dealt.
This doesnt work for me because it is my enemy who is colliding so it will kill my character. i think need to return the Cdmg to 0 after 1 use but i dont know how.
 
Last edited by a moderator:

Danei

Member
Do something like,


Code:
// in collision check

if (canCollide) {
   other.hp -= 25;
   canCollide = false;
   alarm[0] = 60;         //or a different alarm if you're using this already


}

// in the alarm you're using
canCollide = true;
You'll probably want to initialize canCollide to True in your enemy's create event as well.
 
B

Bengs

Guest
Do something like,


Code:
// in collision check

if (canCollide) {
   other.hp -= 25;
   canCollide = false;
   alarm[0] = 60;         //or a different alarm if you're using this already


}

// in the alarm you're using
canCollide = true;
You'll probably want to initialize canCollide to True in your enemy's create event as well.
Ty for replying i've created a hitbox
Code:
            hsp = 0;
            x = x + hsp;
            image_speed = 2;
            sprite_index = Spr_CharacterAttack01Right;
            instance_create_layer(x,y,Obj_Character,Obj_CharacterAttack01RightHitbox);
            if (image_index > image_number - 1){
            attack = 0;
            }
and then in the obj_hitbox this code
Code:
with other{
    Ehp -= Obj_Character.Cdmg;
    }
    instance_destroy(Obj_CharacterAttack01RightHitbox)
In my character create code i put
Code:
Cdmg= 50;
In my enemy create code i put
Code:
Ehp = 100;
But nothing appears to happen. Could you please help
 
B

Bengs

Guest
Do something like,


Code:
// in collision check

if (canCollide) {
   other.hp -= 25;
   canCollide = false;
   alarm[0] = 60;         //or a different alarm if you're using this already


}

// in the alarm you're using
canCollide = true;
You'll probably want to initialize canCollide to True in your enemy's create event as well.
I also put this in my enemy step code btw

Code:
if Ehp <= 0 {
instance_destroy()
}
 
What Event have you put the
Code:
with other{
   Ehp -= Obj_Character.Cdmg;
   }
   instance_destroy(Obj_CharacterAttack01RightHitbox)
code into?
 
Top