Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnCollisionExit2D not working

Discussion in 'Scripting' started by mightybob, Apr 16, 2014.

  1. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Trying to figure out what I am doing wrong here, could someone help me?

    PHP:
    function OnCollisionExit2D (colInfo Collision2D) {
        if (
    colInfo.collider.tag == "ground")
        {
            
    Debug.Log("not touching ground");
                    
    touchingGround false//this boolean is declared in a different part of the code
        
    }
    }
    I've tagged all game objects I want it to recognize as "ground", OnCollisionEnter works just fine, but OnCollisionExit won't work. I am doing it exactly as it says I should in the documentation, isTrigger is set to false, I've tagged them, they have 2D box colliders, what am I doing wrong here?
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Is the debug still not called if it is placed outside of the tag check?
     
  3. Joker_54

    Joker_54

    Joined:
    Nov 24, 2013
    Posts:
    64
    If you are using Objects by transforms, you wont get any Exit or Enter calls. Try rigidbody2D.velocity or .addForce
     
  4. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Thanks joker, i think thats my problem. i'll try that out.
     
  5. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Now when I use rigidbody2D's velocity X, the player moves super choppy.

    Any ideas how I can fix this?

    EDIT: Just read a post about it, someone says its an "illusion"... if this was an illusion, i'd notice the exact same thing when using transform.position.x.
    Who the heck came up with the idea to stop all collisions if you're using transform?
     
    Last edited: Apr 17, 2014
  6. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Okay, I fixed the choppiness now, I set the camera X to always be the same as the players X, now I don't notice any choppy movement. Now I just have to change the rest of the collider objects to use rigid body's and I think it'll be fixed!

    Thanks for the help!