[Collider Configuration] Flawless Dual Setup for Blocking & Triggers
Solution
Unity 2021.x - Unity 6.3.x
Published Wed, Mar 11
An object configured with a Mesh Collider that has its isTrigger property enabled allows objects to pass through it, preventing physical obstruction. Conversely, if isTrigger is disabled, physical obstruction occurs but trigger events, such as OnTriggerEnter, will not fire. Additionally, improper handling of dynamic Rigidbody movement can lead to collisions being ignored by the physics engine.
To implement an object that is both solid and capable of triggering events, a two-collider approach is recommended. This setup ensures that the physics engine handles both spatial occupation and event notification independently.
- Attach a
Collidercomponent to your object to define the primary physical boundaries. - Ensure the isTrigger property is disabled on this specific collider to block movement.
- Create a child
GameObjector add a secondaryCollidercomponent to the primary object. - Enable the isTrigger property on the secondary collider to handle event detection logic.
- Scale the trigger collider dimensions to be slightly larger than the solid collider to ensure
OnTriggerEntersignals are received reliably before or during contact.
When moving your script logic for a dynamic Rigidbody, use Rigidbody.AddForce rather than directly modifying Transform.position. Bypassing the physics engine via position overrides often causes the isTrigger callbacks to fail or objects to tunnel through solid geometry at high velocities.
Additional Tips
- Enable
Interpolationon theRigidbodycomponent to prevent visual stuttering when physics forces are applied. - Set
Collision DetectiontoContinuousfor fast-moving objects to prevent them from passing through geometry. - Configure the
Physics Layer Collision Matrixto ignore collisions between the solid and trigger layers if they occupy the same space to reduce overhead.
TL;DR
To achieve both solid collision and trigger functionality, utilize two colliders: a non-trigger for physical obstruction and a separate, slightly larger trigger for event detection. Dynamic Rigidbody movement should use AddForce.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.