GML 1 hit kill

Discussion in 'Programming' started by Bengs, Nov 8, 2018.

  1. Bengs

    Bengs Member

    Joined:
    Nov 4, 2018
    Posts:
    18
    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
    }
    
     
  2. JeffJ

    JeffJ Member

    Joined:
    Jun 20, 2016
    Posts:
    322
    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.
     
  3. Bengs

    Bengs Member

    Joined:
    Nov 4, 2018
    Posts:
    18
    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: Nov 8, 2018
  4. Danei

    Danei Member

    Joined:
    Mar 23, 2018
    Posts:
    278
    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.
     
    Toque likes this.
  5. Bengs

    Bengs Member

    Joined:
    Nov 4, 2018
    Posts:
    18
    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
     
  6. Bengs

    Bengs Member

    Joined:
    Nov 4, 2018
    Posts:
    18
    I also put this in my enemy step code btw

    Code:
    if Ehp <= 0 {
    instance_destroy()
    }
    
     
  7. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,184
    What Event have you put the
    Code:
    with other{
       Ehp -= Obj_Character.Cdmg;
       }
       instance_destroy(Obj_CharacterAttack01RightHitbox)
    
    code into?
     
  8. Bengs

    Bengs Member

    Joined:
    Nov 4, 2018
    Posts:
    18
    Into the colission code between my hitbox and my enemy
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice