- Home /
Simultaneous Hits
I'm in the process of making a top down shooter game and I have a fairly complex (for me, anyway) spawning script to handle...spawning. The spawning script has just one flaw: it relies on the defeated bad guys to report back to the spawning script when they're dead and gone.
There are times it works too well.
An example bit is here:
function ApplyDamage (shotDamage : int) {
hitPoints -= ShotWeapon.shotDamage; if (hitPoints <=0.0) { NPCSpawning.currentEnemy -=1; NPCSpawning.playerScore +=2; Destroy(gameObject); } }
Basically, the bad guy gets hit by the shot from the player, takes damage and if its enough to kill him he reports back, adds to the score and destroys himself.
So far so good.
Unfortunately, the player has access to a "spray" type of weapon. Like in Super Contra, or Smash TV and I'm sure every other game in the genre. When multiple bullets hit the bad guy (and kill him), the bad guy "dies" many times--once for each bullet.
In a game that's supposed to have 8 on screen it's possible to get in to the twenties. Easily.
Therefore, my question is this:
How do I fix it?
Answer by matyicsapo · May 05, 2011 at 07:38 AM
could just add sg. like bool isAlive;
and set it to false where you call Destroy and also add it to the condition so it only ends up true if hitPoints<=0 && isAlive
is true too
I thought of this, but dismissed it because I figured if it didn't get to the destroy first (before reporting back) that it wouldn't change behavior.
I'll give this due diligence and try this.
That worked. Apparently being two lines above helps. I guess I should have tried and tested that rather than give up and post here. Oh well, maybe someone else will learn from this down the road.
Your answer
Follow this Question
Related Questions
Enemy(sphere) spawn and die over time 1 Answer
How to respawn items along with player 1 Answer
In My Multiplayer Game only he host Respawns when he dies 0 Answers
Random Spawning 1 Answer
How do i spawn object after it has been destroyed? 2 Answers