- Home /
Unity2D game objects don't collide
I made two objects and attached a BoxCollider and a RigidBody2D component to each of them.
In the code associated with object 1, I have
void FixedUpdate(){
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (1.0f, 9.8f),
ForceMode2D.Force);
}
void OnCollisionEnter(){
Debug.Log ("Collision");
}
and in the code associated with object 2, I have,
void FixedUpdate(){
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (-1.0f, 9.8f),
ForceMode2D.Force);
}
And when I play, the objects move toward each other, seem to physically touch each other, and then rotate away from each other. Nothing is logged, OnCollisionEnter is never entered into?
It depends on what object collided with which one, because the "OnCollisiobEneter()" will only occur when OBJECT 1 collides first...
taxi's answer is right you need to change OnCollisionEnter to be 2D. Also a box collider will not work. You need to add a 2D BoxCollider!
Answer by taxvi · May 29, 2015 at 12:53 PM
because Rigidbody2D is triggering OnCollisionEnter2D(Collision2D col) instead of OnColisionEnter
Your answer
Follow this Question
Related Questions
Character slows down when running against a wall (2D) 1 Answer
testonCollisionEnter2D testwon't testget called on collison 2 Answers
Collide detection with tag [JS] 0 Answers
Collision of child is detected as collision of parent with Rigidbody2D 0 Answers
My rigidbody2d is passing through the side of a collider2d but it's working on the top 0 Answers