-
-
Notifications
You must be signed in to change notification settings - Fork 21k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global rotation can return opposite sign of expected. #21020
Comments
I have encountered this before, it has to do with the way the values are stored in the transform matrix. |
@dualmatrix Thanks for sharing that. I agree, that it would be nice if the global_rotation (scale as well?) would handle the extra step. It isn't so intuitive when you run into this thinking you'll save some coding time with managing rotating parts belonging to a character that relies on flipping its scaling. The testing starts out fine when going in positive X direction, but when you turn around all hell breaks loose. XD |
Might have to do with orientation, see this comment from
This definitely should appear prominently somewhere in the docs I guess. |
No , it has to do with the way the rotation, scale and position are being stored in a Transform matrix, and since a negative scale + rotation is mathematically identical to a positive scale + another rotation so the code can't distinguish the two. |
@poke1024 The orientation in the example project I believe is correct. It's more of an issue with the rotation being flipped and not taking into account the scaling of the parent when it's negative. Was wondering if it may have been related to your issue, since you were having problems with inverted transforms. I'm not very well versed in the matrix math, but for now I'm using a work around that goes something like this (though it may be naive):
|
@avencherus Ok, this is a different issue from mine then, and not one of orientation, as @dualmatrix notes. As composition, both scale-rotations are identical and correct, it's a matter of convention which to choose, and Godot's convention doesn't match with the convention you need in your use case. This code might be related:
You could try to skip the flip in the implementation above, extract the rotation yourself, i.e. do a |
Any updates? |
This is a duplicate of #17405. The symptoms are different, but the cause is the same: Negative X scales can't be decomposed from a transformation matrix, and negative X scales get encoded in the transformation matrix as a rotation, therefore negative X scales have problems like these and should be discouraged or disallowed. |
When you have a node belonging to a parent using scaling with a negative X (or Y), the global rotation seems to be putting out the wrong sign and flipping the rotation.
When both scaling X and Y are the same sign (positive or negative) it will appear correct, but when only one component of the parent's scaling is negative the global rotation of the children will have the opposite sign of that scaling.
The canvas item will render with no issue, but the global rotation value it returns will give the following:
Red is what happens in the SceneTree, the Green arrow is using the global rotation value given by the Red arrow. The Green Arrow is not parented to the Red and isn't inheriting any rotations, see the sample project for more details.
I don't know if this is something intentional, but looking at the output of the global transform's scaling, I wonder why the Y component has a negative value rather than the X. Maybe the scaling is flipped up somewhere?
Is this behavior intended, expected, or is it actually a bug? It tripped me up quite seriously. I assumed this far that the point of global xform references were that they would be taking into account all the transformations of the parents.
This is from a master branch build (3.1) I compiled yesterday, and I'm running everything in the context of Windows 10 with 64 bit versions.
It also seems to be present in previous versions.
Does it have anything to do with the problems seen here?: #20966
A 3.1 sample project:
Neg X Scale Global Rotation.zip
The text was updated successfully, but these errors were encountered: