Search Unity

2d trigger events not working properly when a 2d collider is animated (Unity 4.5)

Discussion in '2D' started by latamakuchi, May 29, 2014.

  1. latamakuchi

    latamakuchi

    Joined:
    Jan 16, 2013
    Posts:
    2
    Hello! I was wondering if you could help me out. I don't know if this is only happening to me, if I'm doing something wrong or if it's a known bug. I couldn't find anything useful in the answers so far, I apologize if someone has already asked this.

    I have a game object (a check point of sorts) with a script attached that detects when the player collides with it. It's a static object so it only has a box collider 2d set to is trigger, and this code inside the script:

    Code (csharp):
    1. void OnTriggerEnter2D(Collider2D other) {
    2.     if(other.gameObject.tag == "Player"){
    3.         // do something cool
    4.     }
    5. }
    Really simple stuff. Everything worked fine (OnTriggerEnter2D was called once when the player hit the check point, like it should, and I was a happy person). Then I tried to animate the player's box collider 2d (which I need to do when he's crouching or crouch sliding) and now OnTriggerEnter2D is called multiple times (and OnTriggerExit2D none at all, btw).

    Like I've said, the check point has only a box collider 2d set to is trigger (an the script for handling the trigger event), and the player has a box collider 2d and a rigidbody 2d (someone in another thread had issues because of a lack of a rigidbody, but that's not the case here).

    Does anyone know what could be wrong or how to get the triggers to work with an animated collider (if a solution even exists)? I need to animate the collider and I'd rather avoid having to create a nasty workarround with booleans or something.

    I'd really appreciate your help!
     
    Last edited: May 29, 2014