Search code examples
unity-game-engine2dunity2.0

Disable psychics collisions and leave trigger detection in Unity2d


I have two objects with RigidBody2D and two BoxColliders (2D) first is trigger second is collidable i want to turn off psychical colliding between this two objects (i need it to objects stay at ground) and leave trigger detection working in code.

I tried to Exclude layers in rigid body but it also turned off trigger detection in code For example: I have script

...
private void OnTriggerEnter2D(Collision2D coll) 
{
    Debug.Log("Triggered");
}

Before changing excluding layer it works well but colliding is on When i change everything turnes off (trigger detection and collision)

Anyone knows how to achieve this?


Solution

  • Have you tried using layers? To achieve objects with box colliders that do not physically collide but still detect trigger events, you need to use different layers for the objects and adjust the collision matrix.