BUG #16: Player projectile causes double collision
This bug became apparent after I noticed the sound effect associated with an invader being destroyed, randomly, got much louder. Initially, identifying the cause wasn’t overly obvious. I decided to capture some video whilst playtesting and then review it, looking specifically at the events where the audio became louder.
It transpired that at the same time the sound effect’s volume increased, two invaders were being destroyed, seemingly, at the same time. Each invader played it’s sound effect so close together that it sounds as if it is a single sound effect with an amplified volume.
In the video below the left hand side of the screen shows Unity’s Scene View, whilst the right hand side shows the Game View. The green outline around each invader in the Scene View indicates it’s BoxCollider2D component. At 00:13 a single player projectile causes multiple collisions.
To resolve this issue I considered, and tried, several approaches to prevent multiple collisions between the player projectile and the invaders, however the success rate of these didn’t prove to be overly reliable.
As a temporary solution I opted to reduce the volume of the BoxCollider2D component on the player projectile. This had the effect of reducing the chance that a player’s projectile could cause a collision with more than one invader.
I plan to revisit this issue and further refine a solution, as despite the frequency of this issue being significantly reduce, on occasion, it does still occur and nobody gets Two For The Price Of One on my watch!