I am experiencing inconsistent behavior using Unity's 2D Physics engine and their Collider2Ds to detect collisions and triggers on my projectiles. I will classify it into two problems. The first is that occasionally the projectile will pass through walls/objects it should collide with. The second is that occasionally the projectile will pass through enemies that it should hit without triggering. I will try to elaborate in detail below.
A projectile is organized into a container Projectile GO and two children GO: a PhysicsColliders GO and a HitBoxColliders GO.
The PhysicsCollidersGO job is to hold the colliders that define the solid regions of the projectile using Collider2D components. It's GO is on a Projectile layer which is set to collide with other solid layers such as the ones my walls are on. Walls are static colliders.
The HitBoxCollidersGO job is to define the a HitBox area. It's GO is on a HitBox layer and also uses Collider2D components that are set to be triggers. A HitScript on the GO listens for OnEnterTrigger.
Projectiles are set in motion by setting the velocity of the RigidBody once upon firing.
Here is a visual of the structure:
ProjectileGO - PhysicsCollidersGO - HitBoxCollidersGO
Here are descriptions of the GameObjects and their components:
ProjectileGO - RigidBody2D Component (collisionDetectionMode is set to Continious) PhysicsCollidersGO (Layer is set to Projectile) - BoxCollider2D Component HitBoxCollidersGO (Layer is set to HitBox) - BoxCollider2D Component (IsTrigger is set) - HitScript Component
Problem 1. Projectiles will sometimes not collide with walls/solid objects/etc...
Problem 2. Projectiles will sometimes not trigger a hit.
What could be causing these inconsistencies? How can ensure that collisions and triggers will consistently behave correctly?