For my 3d game, I don’t require any real physics within the game.
But my cube objects are moving and I require to detect their internal collisions.
As I understand, every moving collider object must require rigidbody within it. So I have attached my all moving cube objects kinematic rigidbody like this:
Now how to detect collision for two kinematic rigidbodies?
I don’t want to convert it to non-kinematic body otherwise physics started applying on them.
Configure “Project Settings > Physics > Contacts Pair Mode” to “Enable All Contacts”
Move your kinematic bodies using Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate.
Now the collision events (OnCollisionEnter, etc) will happen normally as with standard rigidbodies.
Since Unity 5 this is no longer a hard requirement. The documentation is outdated about this. You can have static colliders moving in your scene without performance penalties.
However, if you need your moving colliders to cause physically correct effects on other objects, then you should move them as described above.
Your reply made me more confused, just a few days ago I watched the latest GDC video they are clearly saying we must have to attach a rigidbody component to the GameObject which has collider attached and moving.
Otherwise, you will get a performance problem and there is a movement issue too.
I can’t able to find specific video related to this topic and it was not old Unity 5 version video.
@Edy
Hey Edy, you saved my ass a few times yet!
When it comes to physics in unity it seems you always have a solution or tipp… you truly are a wizard and a big contribution to this community!
I’m using another vehicle physics system (NWH) for now and it works great for me, but I’m going to purchase your asset anyway soon! Just because… shit… your posts helped me a LOT!!
Thank you for your contribution and keep going!
Michael
@Edy Thanks for this one, made my collisions work by changing it to “Enable Kinematic Kinematic Pairs”
Now I’m a bit confused about this part
I was under the impression that isKinematic should be used when you want to move your objects by Transform but still need to be able to detect collisions. Is there a reason why you should use Rigidbody.MovePosition instead ?
Modifying the Transform means teleporting the object overriding the calculations of the physics solver. This won’t provide the correct physics effects, friction for example. You shouldn’t modify the Transform on any Rigidbody unless there’s a justified reason to do so (i.e. teleporting an object back to it’s startup position is a justified reason).
For example, imagine a non-kinematic cube sitting on top of a kinematic cube:
Moving the kinematic cube with Transform: the non-kinematic cube stays steady in the scene and eventually falls when the kinematic cube has moved enough.
Moving the kinematic cube with Rigidbody.MovePosition(): the friction force has effect so the non-kinematic cube keeps “fixed” on top of the kinematic cube, unless this one moves fast enough to overcome the friction.
Additionally, Rigidbody.MovePosition (and Rigidbody.MoveRotation) support the Rigidbody interpolation options, so visual motion remains smooth at any time scale and frame rate.