GMS 2 making player invincible after taking damage

Discussion in 'Programming' started by Pedau666, Jan 20, 2018.

  1. Pedau666

    Pedau666 Member

    Joined:
    Dec 11, 2017
    Posts:
    30
    I have a problem with making player invincible after taking damage from enemy. I want player to be invincible for 2 seconds after hitting the enemy and losing 1 hp. The event looks like this for now and I don't know how to end it. Can you guys help?

    ENEMY COLLISION WITH PLAYER EVENT
    ENEMY ALARM 0 EVENT
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    In the collision event of the enemy object with the player object, you set the alarm[0] of the player to 0, not of the enemy.
    There also no reason why you should need an alarm to activate the player's invincibility.
    Just remove the alarm event and change this line in the collision event:
    Code:
    alarm[0] = 0
    to this:
    Code:
    inv = 60;
    Then add in the step event of the player these lines:
    Code:
    if inv > 0 {
        inv -= 1;
    }
    Now inv will hold the remaining amount of steps the player will be invincible and 0 if they're no longer invincible.

    EDIT:
    If I correctly understand what your flash variable is for, then you won't be needing that anymore either.
     
    LoadingDevelopment likes this.
  3. Pedau666

    Pedau666 Member

    Joined:
    Dec 11, 2017
    Posts:
    30
    thank You so much, it worked
     

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