Currently I'm trying to let the player place a GameObject in the world. You can imagine this like a RTS game where you can place a building you have just build.
My problem now is, in order to avoid that the new GameObject intersects with another I check for collisions. For this my GameObjects have a BoxCollider (MeshCollider did not work) and a non kinematic RigidBody.
The first tests looked promising but now I'm facing a problem I can't quite explain: Sometimes, but not always OnCollisionEnter and OnCollisionExit are called over and over again, even when both objects are not moving. They overlap and stay that way. I had guessed that they always only get called once.
My Unity version is 5.3.0f4.
Further information: Each of my GameObjects have a guid so I can identify. They get generated when the GameOject is created. The debug output in OnCollisionEnter and Exit look like this:
OnCollisionEnter from 593b209f-cc63-4d31-9911-34c5f69ac224
Collided with: 77e05881-2adb-459d-a134-8205cf4e3327
OnCollisionEnter from 77e05881-2adb-459d-a134-8205cf4e3327!
Collided with: 593b209f-cc63-4d31-9911-34c5f69ac224
OnCollisionExit from 593b209f-cc63-4d31-9911-34c5f69ac224!
OnCollisionExit from 77e05881-2adb-459d-a134-8205cf4e3327!
And then the same output again.
I'm happy for any hints and help. :)
transform.positionevery frame? Because this causes the Rigidbody to basically "leave" its current position and "enter" anew. If so, try using Rigidbody.MovePosition instead, which is the cleaner way to move an object that has a Rigidbody. \$\endgroup\$