Hello. I have a prefab with kinematic RigidBody. I rotate my prefab along a path after instantiation and in the next lines of code I need to get current prefab rotation and positions of child objects.
print("Rotation: " + locomotive.transform.eulerAngles);
Quaternion myrotation = Quaternion.Euler(0, 180, 0);
locomotive.GetComponent<Rigidbody>().MoveRotation(myrotation);
print("Rotation 2: " + locomotive.transform.eulerAngles);
After executing these lines of code in the console I see:
Rotation: (0.00, 0.00, 0.00)
Rotation 2: (0.00, 0.00, 0.00)
But the game object has a rotation (0, -180, 0) in the inspector and correct rotation in the scene. Why do I get similar zero rotations before and after rotation in the log? This game object is not a child of another game object. World position of child object of “locomotive” game object is not changed in the log after rotation too.
If I use this method to rotate object:
print("Rotation: " + locomotive.transform.eulerAngles);
locomotive.transform.Rotate(0.0f, 180.0f, 0.0f, Space.World);
print("Rotation 2: " + locomotive.transform.eulerAngles);
Then in the console I see:
Rotation: (0.00, 0.00, 0.00)
Rotation 2: (0.00, 180.00, 0.00)
But in the scene instantiated kinematic game object has rotation (0, 0, 0) in the scene.
If I use a combination of these two methods:
print("Rotation: " + locomotive.transform.eulerAngles);
Quaternion myrotation = Quaternion.Euler(0, 180, 0);
//locomotive.GetComponent<Rigidbody>().MoveRotation(myrotation);
locomotive.GetComponent<Rigidbody>().rotation = myrotation;
locomotive.transform.Rotate(0.0f, 180.0f, 0.0f, Space.World);
print("Rotation 2: " + locomotive.transform.eulerAngles);
Then rotation in the scene (0, -180, 0) and in the log
Rotation: (0.00, 0.00, 0.00)
Rotation 2: (0.00, 180.00, 0.00)
I instantiate prefab by clicking on UI button.