Search code examples
gmlgame-maker-studio-2

Im having problems with the collisions im GMS2 using GML


Theoretically, when I touched an enemy I would lose one life and from three hearts I would have 2. What happens is that when I collide with him, the lives are all lost restarting the room because I have to when I reach 0 lives, the room restarts. I'm using GMS2 and using GML, I don't know anything about DnD... Here´s my code to collision with enemy:

//create event
 global.lifes = 3
//collision event
 global.lifes -= 1

Solution

  • You'll need to implement an invulnerability function, that'll prevent the player character from getting damaged again on the next frame.

    The most simple one would be a timer that counts down if you got hit, and if that timer is still counting down, then ignore the Collission Event.

    See also my answer here about adding invincibility in GMS2: https://stackoverflow.com/a/62769522/2735344