- Home /
The question is answered, right answer was accepted
OnCollisionEnter not triggering when two rigidbody collide via Instantiate
Trying to figure out how to get onCollisionEnter to trigger when two rigidbody objects collide.
I have a rigidbody unit sphere sitting at the origin (gravity off). When it's pressed, another rigidbody unit sphere is instantiated nearby. The two bounce off but onCollisionEnter is not triggered. How do you get the collision to detect?
function OnMouseDown(){ var o:GameObject = Instantiate(t2,transform.position+Vector3(0,0,0.5),Quaternion.identity);
}
Updated, where the spawned rb does not initially collide with the other:
function OnMouseDown(){ var o:GameObject = Instantiate(t2,transform.position+Vector3(0,2,0),Quaternion.identity); o.rigidbody.useGravity = true; }
I believe that OnCollisionEnter is not executed if you instantiate the rigidbody already colliding with another rigidbody. They must be not colliding and then start colliding.
Try OnCollisionStay to see what happens.
I just tried it where the instantiate is not touching but force of gravity pulls it down to cause collision... still nothing form oncollisionenter
Ah, it looks like I drove myself crazy for the wrong reason -- to used to Flash... It's OnCollisionEnter
with the On in caps and not onCollisionEnter
... doh! :-O
Follow this Question
Related Questions
Why OnCollisionEnter cannot detect collisions between colliders? 1 Answer
simple onCollision and onTrigger problem 1 Answer
Cannot get collision to do anything 1 Answer
Which Object Calls OnCollisionEnter()? 3 Answers
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers