- Home /
Collider2Ds on projectiles are inconsistently triggering and colliding
Hello! I am experiencing inconsistent behavior using Collider2Ds to detect collisions and triggers on my projectiles. I will classify it into two problems. The first is that ocationally the projectile will pass through walls/objects it should collide with. The second is that ocationally the projectile will pass through enemies that it should "hit" with out hitting them. I will try to elaborate in detail below.
A projectile is organized into a container Porjectile 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.
Any ideas why?
Your answer
