Search Unity

Question Toggle enable collison in SpringJoint2D trigger OnTriggerEnter2D/OnTriggerExit2D

Discussion in 'Physics' started by KerwishYD, Jun 2, 2021.

  1. KerwishYD

    KerwishYD

    Joined:
    Oct 7, 2020
    Posts:
    2
    Hi,

    We faced a problem where we wanted to snap our character to a valid place to start an animation. I've tried using SpringJoint2D with collision disabled (we need to be sure that the character will appear in place after a short period of time).
    I found that toggling enable collison triggers OnTriggerEnter2D/OnTriggerExit2D, which I think is misleading because Triggers and Collisons shouldn't interfere with each other. I wanted to know if it's done by design or if it's a bug -- and what I can do about it.

    Best regards,
    Miłosz Bednarski
    Yellow Dot Games
     
    Last edited: Jun 2, 2021
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    It's not a bug, it's exactly what it does. Collision/Collide/Contact/Touch are all overload and overused (IMHO) so while I can understand some confusion, it's not misleading. OnCollision is just a name of a callback, the word collision here isn't related to a specific callback name. Sure we could change the property to "Enable Contact" but that would still confuse other users because they'd say there are no contacts on triggers. It's hard to be perfect unless we invent yet another term like "interact".

    There's nothing to be done, it's working perfectly. You're stopping contacts by turning it off.

    Note that this directly represents the Box2D "CollideConnected" feature for joints.
     
  3. KerwishYD

    KerwishYD

    Joined:
    Oct 7, 2020
    Posts:
    2
    Thanks for quick reply! I assumed that using the flag determined whether the collisions happened or not when using the spring. But I didn't expect it to disable all colliders (even when they were marked as triggers). So now I can't really think of any case in which the flag should be used. Could you give me some examples?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You might have a rope consisting of multiple bodies/colliders where you don't want it to interact with itself. In this case you'd turn this option off.

    If you don't want the colliders on the two attached bodies to interact (basically ignore each other) then uncheck this option. It doesn't care if they're triggers or not because being a trigger isn't a special case.

    If your case is the same then turn it off. There's no separate don't trigger or don't collision option in the underlying 2D physics engine. The joint isn't associated with any collider, it's associated with the Rigidbody2D it's attached to and therefore all the colliders which are attached to the Rigidbody2D.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    And just to be clear, it's only stopping those two bodies from interacting with each other and nothing else.