Search Unity

rigidbody2D.isKinematic and OnCollisionEnter2D bug?

Discussion in '2D' started by LawnOni, Mar 17, 2014.

  1. LawnOni

    LawnOni

    Joined:
    Oct 17, 2013
    Posts:
    5
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class testecollider : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         rigidbody2D.isKinematic = true;
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.  
    15.     }
    16.  
    17.     void OnCollisionStay2D(Collision2D coll){
    18.         Debug.Log("Entered OnCollisionStay2D");
    19.         rigidbody2D.isKinematic = false;
    20.     }
    21. }
    22.  
    Well.. without the "rigidbody2D.isKinematic = false;" everything run ok!

    But... with that line, when I collide with the object at the first time, the method OnCollisionStay2D is called.. and it's called forever.. even when I'm not colliding.
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    What do you mean forever, when not colliding... You collide, the object becomes Kinematic, and should stay put, so how does it stop colliding?
     
  3. LawnOni

    LawnOni

    Joined:
    Oct 17, 2013
    Posts:
    5
    The two objects are far from each other, and the OnCollisionStay2D continues to be called.

    But it happens only when the two objects collides for the first time.

    Two objects: Player and Box. Both have rigidbody2D and boxcollider2D.. The player is controlled by input.
    They don't begin colliding. When they touch each other the OnCollisionStay2D is called and the Box rigidbody2D.isKinematic becomes false.

    Then, I stop the player colliding with the box, but the Box OnCollisionStay2D continues to be called...
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Oh ok, yeah this is an existing bug that's supposed to be fixed in the next update... whenever it comes out. I'm guessing when you change player direction, you're scaling * -1, like in the Unity example, correct? Scaling out of a trigger keeps the Exit function from happening, so it thinks you're still triggered... It's pretty core mechanics breaking.