0
\$\begingroup\$

My player in unity2D has a system to check whether it has collided with any harming substances such as fire, villains etc. When it is true that condition, it Re-Spawns to a certain position. It also decreases the amount of life that the player has. for eg:- At start my player has 15 such lives and each time any harming object as I have mentioned before, collides with my player, it decreases to 14 and so on.

But, In certain places I have fire along the way which is made up of many object as the image shows :-Fire

And, when the player collides with this fire, it decreases the lives 4-5 more because it has collided with more than one object. So, how can I make such that my player's life will only be deducted by 1 in this condition?

\$\endgroup\$
0
\$\begingroup\$

Do you mean respawn as in re-spawning at a point earlier in the game? Or re-spawning as in the player gets thrown back upon collision as in being hit, but not dying?

A quick fix would be to lock the player collision detection upon collision. You'd simply introduce a bool, which is checked upon collision and if it's false, you enter the code and set it to true immediately so the next checks all fail. Once you respawned the player, you'll set the bool back to false and "enable" collision detection again.

Alternatively, instead of creating a wall of flame with many gameobjects, each with their own collider, you could create a wall of flames with just one collider and just make it look like there are many single flames.

\$\endgroup\$
  • \$\begingroup\$ Thanks! That Alternative process worked just fine. For those stumbling, just take any object (fire) from bunch of those objects and add a collider and edit it to your extent and it works just fine. \$\endgroup\$ – Sabin Pyakurel May 7 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.