- Home /
C# OnCollisionEnter2D Not Occuring
I have two gameobjects both with the same OnCollisionEnter2D script but for some reason when they collide OnCollisionEnter2D doesn't occur. I have not received any errors from the console so I'm unsure what is causing this.
void OnCollisionEnter2D(Collision2D other)
{
other.gameObject.rigidbody2D.AddForce(-transform.position * 100);
rigidbody2D.AddForce(other.transform.position * 100);
}
Edit: I've found out that if you comment either lines of code it works fine but if both are running then it doesn't execute at all. I still haven't found a way for both to be working at the same time.
Do they both have Collider2Ds? (Stupid question, I know)
Does at least one of the items have a rigidbody?
What version of Unity are you on? (<4.5 has a bug with Is$$anonymous$$inematic)
Answer by pabloj100000 · Feb 22, 2015 at 05:30 AM
I am new to Unity but I think one of the object has to have a RigidBody component for collisions to take place
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
,Fast Moving Gameobject Collision and Trigger Check Failed 0 Answers
Object jumps right after the attached HingeJoint2D is Enabled 0 Answers
Collision issue with SetParent (C#) 1 Answer
Adding 1 frame of force 2 Answers