When you add a Rigidbody2D to a GameObject, and rotate the transform at edit time or runtime, the Rigidbody2D updates it’s .rotation value to match the transform.
How exactly is this calculated? It seems to not just be .eulerAngles.z, since you can get pretty different values from that if you rotate the transform around other axes than the z-axis.
The reason I’m asking is because I have a script that does some things relative to a Rigidbody2D’s rotation, and I’m drawing some gizmos to show the directions. In one instance, the Rigidbody2D is added at runtime, so I want to show the gizmos relative to the rotation the body will have when that happens. Any help appreciated!
Probably the best way to show you the composition/decomposition of Z when dealing with quaternions is to show you this bit of code that uses the Unity math package. Maybe this will be of some use as it does essentially the same thing as is done in the C++ code.
Those matrices are 2D Physics → Transform, while I need the other way around, ie “if I added a Rigidbody2D to this transform, what would it’s rotation value be?”
I can fudge it since these objects are currently expected to only be rotated on the z-axis anyways, but I want to not have to go back and fix things if that’s not the case anymore.
(this was an answer to the first of your two posts!)