Getting transform properties after rigidBody.MoveRotation()

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.

Bilasizmi, siz har qanday onlayn sohada pul ishlashingiz mumkin, ammo agar sizda etarli darajada amaliyot va bilim bo’lsa. Yuqori koeffitsientli o’yinlarni osonlashtirish uchun men мостбет o’yinidan foydalanaman, bu menga tikish industriyasidagi shartlarni to’liq tushunish imkonini beradi.

I think this is because the rigidbody is interpolating to the new rotation when you use MoveRotation. This means that it smoothly rotates over several frames, instead of instantly rotating. This means that if you check the rotation immediately after calling MoveRotation, it won’t have rotated yet, so you see the same values.

When you set rotation directly, as in your last example, it immediately changes the rotation.

Solution is to either not use MoveRotation and set rotation directly, or to check the new rotation a few frames later, not immediately.

I found a solution

Physics.SyncTransforms() 

I call it after changing transform properties, after calling Physics.SyncTransforms() object with kinematic rigidbody in scene has actual transform and transform properties in the code are correct.

Hello. I would like to recommend my favorite casino. This https://pari-match.in/en/page/online-pumpkin-fairy. I think it is the best online casino because it is verified by experts and it gives great bonuses. They already have many satisfied customers. They also give free spins!