Hi,
After days of research, I am finally able to reproduce an interesting issues both with Unity 4 and Unity 5. Apparently the RigidBody code doesn’t have any safeguard check to protect itself from the application of very huge forces.
When very huge forces are applied (usually due to singularities due to bugs), the Rigid Body game object is shot out of the Unity world where the Unity physic laws known are meaningless. Strange things start to happen. For example:
from the Unity documentation, I can see that the following code is valid:
transform.position = new Vector3(0, 0, 0);
print(transform.position.x);
my code just does this:
go.transform.position = Vector3.zero;
Debug.Log("***********************RESET TRANSFORM********" + go.transform.position.x + "*************" + go.transform.position.y + "**********" + go.transform.position.z);
go.transform.position = b.center;
Debug.Log("------------------SET TRANSFORM----------" + go.transform.position.x + "-----------" + go.transform.position.y + "-----------" + go.transform.position.z);
which usually works. However under the given reproduction circumstances, the console output is actually the following:
***********************RESET TRANSFORM********1.28849E+10*************-8.053088E+09**********-1.073742E+09
------------------SET TRANSFORM----------1.28849E+10------------8.053088E+09------------1.073742E+09
During the Reset step, the position is actually not set to 0 (wuuut?)
Now, this happens because the parent transform, where the RigidBody is, has also huge position value and in this case, probably, somehow, Unity code gets confused.
If we reset manually the position of the RigidBody gameobject to 0,0,0, then everything works.
So I wonder, wouldn’t be wise to add some code to protect the Rigid Body from being set to this undefined state?