UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

physics

[Collider Configuration] Flawless Dual Setup for Blocking & Triggers

Solution

physicscollisionrigidbodytriggers

Unity 2021.x - Unity 6.3.x

Published Wed, Mar 11

Issue

 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.

Explanation

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.

  1. Attach a Collider component to your object to define the primary physical boundaries.
  2. Ensure the isTrigger property is disabled on this specific collider to block movement.
  3. Create a child GameObject or add a secondary Collider component to the primary object.
  4. Enable the isTrigger property on the secondary collider to handle event detection logic.
  5. Scale the trigger collider dimensions to be slightly larger than the solid collider to ensure OnTriggerEnter signals 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 Interpolation on the Rigidbody component to prevent visual stuttering when physics forces are applied.
  • Set Collision Detection to Continuous for fast-moving objects to prevent them from passing through geometry.
  • Configure the Physics Layer Collision Matrix to 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.