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
-
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
- Fixing Message Loss in UMPE During Domain Reload
- The Editor freezes when ScheduleReadOnly of IJobParallelForTransform with dependency is used
- Text is truncated in the Inspector when the display scale is set to 150%
- CancellationTokenSource(<timeout>) has incorrect cancellation status when used in WebGL Player
- VFX property value names are cut off when properties with 'Arc' are viewed in the VFX Blackboard
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.