- Home /
OnCollisionEnter called once even with multiple contacts
I have a complex mesh which has multiple contact points for it to rest on the terrain, however it only calls OnCollisionEnter once when the first contact point hits the ground, when the other piece hits the ground nothing happens. The mesh is a piece of twisted metal like from a wreck.
I need this to play a sound when the object collides so it seems unrealistic when the other contact point hits and no sound is heard. The ground objects and the craft are both using mesh colliders with convex set to true.
Does anyone have an idea how I can fix this?
Thanks.
No one knows huh - is this even the right place to be asking this question? I'm amazed no one else has had this issue.
Answer by syclamoth · May 14, 2012 at 09:04 AM
This is the right place- it's not your fault it's not as busy here as it should be. You are right- OnCollisionEnter only activates when the collision begins, however, the collision is kept track of in the physics engine. Try tracking individual contact points in 'OnCollisionStay' to manage your hit effects.
Ok cool, thanks for the answer. I guess I dismissed OnCollisionStay because I didn't want sounds to be playing continuously but of course I can fix up the logic to prevent that if I can measure the relative force of contact points etc. I will look into it and post a reply if I can get it to work.
Thanks again.
You can't exactly measure relative force, but you can, for example, assume that if there are two contact points very close to one another in consecutive framse, they are the same contact. Come to think of it, this is a feature I should add to my material interaction system...
Your answer
Follow this Question
Related Questions
OnCollisionEnter event seems to be called late. 3 Answers
OnCollisionEnter inside FixedUpdate? 1 Answer
Changing transform.localScale but OnCollisionEnter isn't executed 1 Answer
Collision Query 1 Answer
Location of RigidBody2D on collision 3 Answers