Multiple Projectile Collisions

 Author: Daniel Jackson


  An issue we experienced this week was one with our projectile collisions. Projectile collisions were indeed being registered however, the same projectile and enemy (or player) were registering a collision every frame while in contact. The good news is that we are registering collision properly, the bad news is because we register it properly damage is being applied to the same entity every frame as the projectile is in contact which could make our weakest weapon end up doing thousands of damage possibly one-shotting a boss.

  Luckily, because projectile collisions are only handled in one specific area of our codebase, debugging didn't take very long. To fix the issue I implemented two fixes. The first is a small safety net that doubles as an implementation of an upgrade to the weapons 'piercing'. Most of our weapon's projectiles will hit a wall or entity and disappear, however, some upgrades allow bullets to hit an entity and pass-through allowing the possibility of hitting another target. For this, I gave our weapons a 'pierce count' which is defaulted to zero and when a collision is registered the count is decremented when the count drops below zero the bullet is deleted. This means that when we want to allow the projectile to pass through an entity we simply increment the weapon's pierce count in the upgrades system. The second solution is more expensive but far simpler. To remove the possibility of the same bullet hitting the same target each bullet keeps a list of the enemies it collides with and if it hits an enemy that is already in its list it's simply skipped.

Comments

Popular posts from this blog

Adding assets to every enemy -- Owen Meyers

Sphere to AABB collision