Jump to content

Temporary player invulnerability, turn off collisions for "x" seconds


Mr. Meows
 Share

Recommended Posts

You could do it this way:

 

In the overlap callback, (where you have your 'take damage' code) you set a new variable "invulnerable" to game.time.now

 

Before you call the "take damage" code, you check, that the difference between game.time.now and the invulnerable variable is bigger than the desired invul-time.

 

if (game.time.now - invulnerable > 2000)  {

  //take damage code here

  invulnerable = game.time.now;

}

 

This way you only take damage every two seconds.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...