i can't figure out a way to have an enemy sprite take off a single unit of life inventory from my player character. I have my player sprite having 5 units of health and the colision settings for my enemy sprites are set to take off 1 health if i have 5, one health if i have 4 etc. the problem is the enemy sprite just brings my health down to zero instantly and i can't find away around this other than having the enemy sprite be deleted after it collides with my player sprite. any help would be greatly appreciated.
-guildhall student
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why do you list "1 health if I have 5" and "1 health if I have 4" separately? Why don't you just define the collision to take off 1 health if the player has at least 1 health? That will work whether the player has 5 health or 4 health, etc. If you have multiple collision definitions, it will first take off 1 health if the player has 5, then (in the same frame) it will take off 1 more health because the player still has 4 health. The problem could at least be improved by using a single collision definition rather than multiple collision definitions.
The way some people have solved the rest of this problem is to temporarily switch the player sprite to an invincible sprite when it gets hit. The invincible sprite will not be in the normal player class so it can't collide with any enemies. After a period of time, switch the player back to the normal player.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i can't figure out a way to have an enemy sprite take off a single unit of life inventory from my player character. I have my player sprite having 5 units of health and the colision settings for my enemy sprites are set to take off 1 health if i have 5, one health if i have 4 etc. the problem is the enemy sprite just brings my health down to zero instantly and i can't find away around this other than having the enemy sprite be deleted after it collides with my player sprite. any help would be greatly appreciated.
-guildhall student
Why do you list "1 health if I have 5" and "1 health if I have 4" separately? Why don't you just define the collision to take off 1 health if the player has at least 1 health? That will work whether the player has 5 health or 4 health, etc. If you have multiple collision definitions, it will first take off 1 health if the player has 5, then (in the same frame) it will take off 1 more health because the player still has 4 health. The problem could at least be improved by using a single collision definition rather than multiple collision definitions.
The way some people have solved the rest of this problem is to temporarily switch the player sprite to an invincible sprite when it gets hit. The invincible sprite will not be in the normal player class so it can't collide with any enemies. After a period of time, switch the player back to the normal player.