Hurting the player

NobodyX

  • *
  • Posts: 1228
I made a player character than turns invincible for a short time upon collision with an enemy, and also enemies that reduce the player's health (which is a global attribute) upon collision with the player.

I would think that when the two collide it should recognize the collision for both actors. But if the player actor turns invincible, then the enemy's behaviour does not register any collisions, even though there was one. Getting rid of the player invincibility is not an option.

What do I do?

Greg

  • *
  • Posts: 1260
Can you post a screenshot of the behavior?  What are you doing to make the player invincible?

NobodyX

  • *
  • Posts: 1228
The animations with Hurt in the name have a collision box type that detect tiles only.

Greg

  • *
  • Posts: 1260
So if I understand correctly -

1) Player's normal animation has collision box that collides with enemies
2) Collision occurs, player switches to "Hurt" animation
3) Hurt animation only collides with tiles, not enemies.

Because of step #3, there is no collision box that still collides with the enemy so this is why it's no longer reporting the collision.

You'll probably have to handle invincibility a different way.  Perhaps have another attribute that keeps track of when the player is invincible, and then just don't deduct damage.  If you also want to still detect collisions with enemies while invincible (but with no physical response), create another collision box for the Player and set it to a sensor and then set up that collision box to collide with enemies.

NobodyX

  • *
  • Posts: 1228
I tried making a global boolean that tells enemies not to decrease health when the player is already hurt. After that did not work I tried making it so that the booloean turns on 1 frame later, and now the enemies randomly do no damage, regular damage, or double damage.

Also, how is that a an enemy that bounces using the built in physics will bounce on the players head, but not register the collision to deal damage? (this is when the player's collision shape would change to one the enemy cannot collide with)

Greg

  • *
  • Posts: 1260
I may need to take a look at your game.  This is how I picture it working.

1) Enemy collides with player
2) If invincible, do nothing except decrement the invincible timer.  If the timer is up, mark the player as not invincible.
2) If not invincible, deal damage to the player, set the "invincible" attribute and start the timer.


Greg

  • *
  • Posts: 1260
I think the real issue was the disconnect between checking for a collision on both the Enemy and the Player and trying to coordinate with those. 

Try something like this -- I did some minor testing and it seemed to work.


NobodyX

  • *
  • Posts: 1228
Great! It seems to work perfectly!

Thanks!