Search Issue Tracker
Won't Fix
Votes
0
Found in
2018.4
2019.4
2020.1.17f1
2020.2
2021.1
2021.2
Issue ID
1317525
Regression
No
[Physics2D] Rotating flipped Rigidbody2D leads to constant rotation
Steps to reproduce:
1. Download and open the user's project "Rigidbody2DRotationIssue.zip"
2. Enter Play mode with SampleScene active
3. Use the UI buttons to control the direction of the Rigidbody2D
4. Flip the Rigidbody2D so that it's Y-axis is -180°
5. Click the rotate button
Expected Result: The Rigidbody2D rotates 90° in the Z-axis and continues moving forward
Actual Result: The Rigidbody2D continuously rotates by 90° every fame
Reproducible with: 2018.4.32f1, 2019.4.21f1, 2020.2.6f1, 2021.1.0b10, 2021.2.0a7
Note:
- Added a repro project "Repro 2018.4.zip" for 2018.4 since downgrading the user's project results in a lot of errors
- Possible workaround is to use the Transform.Rotate() function
Comments (1)
-
sztobar
Mar 25, 2021 21:22
I see. That explains why I saw transform.localScale modifications in officual unity guides instead of transform.rotation. Thanks for clarification.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- var VisionOSEDRHeadromm has a comma instead of a dot when building with Metal Rendering App Mode and local OS localization is set to German
- IAP Catalog remove product “x” and add product “+” buttons are not consistent with other remove and add buttons in the Editor
- Performance issues in Play Mode when quickly hovering the mouse cursor over Hierarchy GameObjects
- Frame Debugger displays incorrect output when FidelityFX Super Resolution or Spatial-Temporal Upscaler is used with Temporal Anti-aliasing or Subpixel Morphological Anti-aliasing
- Crash with “Fatal Error! The file ‘MemoryStream’ is corrupted!” when adding a large number in Font Character Rects Size field
Resolution Note:
If you take a look at the Rigidbody2D component in the inspector and open the "Info" foldout you'll see that the body isn't rotating at all. What is happening is that the Quaternion for rotation is providing different solutions to the same rotation causing issues (flipped Quaternion). This isn't dealt with in the physics system.
Inherently this is a 2D system so rotating in 3D space makes it difficult for a system that only has a single degree of rotational freedom (Z).
It is highly recommended that you use Transform.localScale to flip the direction and NOT rotate in 3D space as you can encounter these Quaternion ambiguities.
Here's the change:
public void Flip()
{
#if false
transform.rotation = Quaternion.LookRotation(-transform.forward, transform.up);
#else
transform.localScale = Vector3.Scale(transform.localScale, new Vector3(-1f, 1f, 1f));
#endif
}
With the above change, the Transform quaternion doesn't alternate and cause issues. This issue is one fo the few times this has come up so making major changes in an attempt to deal with this isn't a risk we can take right now.