How do I make the player invincible in during a knock back

Just started using Construct 2? Post your questions here

Post » Tue Jul 05, 2016 9:17 am

Hi all. Simple question. I think. How do I make the player *temporarily* invincible in during a knock back? I found this discussed in other posts but I can't seem to get it working right. I thought disabling collisions of the enemy for a moment during the knockback would work out but I was wrong. The player gets knocked back in a direction depending on where he's facing and the player sprite flashes. How can I make it so that the player is invincible for a moment, isn't knocked back constantly and can walk through the enemy for a moment. Here's the code.

Oh, one more thing before the code. On another slightly related note, what would be the smartest way of creating a health system. By that I mean, should I code player damage numbers and effects (knock back, getting frozen, etc) in the player character sheet or in the enemy character sheet?

edit: added a capx and spelling

Please not how the left worm is not acting as intended. All crawling worms have 3 movement behaviors: it moves and switches direction when near a wall, it moves and switches direction as its about to fall off a platform and it moves and switches direction manually if I set it using collision boxes. The left worm is changing to move right at certain spot and I have no idea why. Any ideas why this is? Looks like the other worms work correctly. Thanks everyone! ... .capx?dl=0

Posts: 179
Reputation: 13,548

Post » Tue Jul 05, 2016 3:24 pm

Have you thought of using a boolean variable and a timer?
You can create an instance variable for the player of boolean type (something like "isInvincible") and local static variable "timer" (the static part is important! It won't work otherwise).
To the initial collision detection add the condition "X isInvicible" (so the player will only be hurt when "isInvincible" is false). And now, when the player is hit, set "isInvincible" to true and set "timer" to 1 second.
Add another event with the condition "isInvincible". This block should countdown the timer, so add the action "Subtract dt from timer" (dt is the value you need to subtract). Add a subevent with the condition "timer < 0", and there make "isInvincible" false again.

If the effects, knockback, freezing and stuff affect the player, program them in the player sheet. If they affect the enemy, program them in the enemy sheet.
Posts: 41
Reputation: 1,131

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests