We all know that physics affects the sense of reality greatly in VR development. As a developer, I always hope to make the physical behaviors of the virtual experience the same as the reality as far as possible. However, I met a problem several days ago. I created a vase with some roses in it, and they are separated Game Objects. However, during the playtest, roses in the vase “jumped out” strangely when I tried to lift the vase. I checked and rebuilt the colliders on the vase and the roses carefully, set the Collision Detection on the Rigidbody to be Continuous Dynamic, tried to bond the roses on the vase as its children, but all of them failed to erase the bug completely. However, my intuition told me that the problem must be related to the physical system, therefore must has something to do with the Rigidbody component.
Later, I noticed that in the Rigidbody component panel, there’s a parameter called Constraints that I never used before.
At the very beginning, I thought such a parameter is for LOCKing the movement on the game object completely. However, it is NOT. Instead, it constrains the Rigidbody to be only allowed to be moved by SCRIPT, rather than physics (or say “inertia”). Therefore, we should enable constraint in these situations:
- When we want to constrain a Rigidbody to only move or rotate along some axes, for example when developing 2D games.
- When we hope the player to have full control of the rotation, for example when holding something, or in first person shooting games.
After I added the condition that to freeze rotation when the object is being held, and unfreeze them when released, the problem was solved perfectly, and the VR world feels more realistic.