-
-
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_scale property wrong in Node2D when scale is negative in x #17405
Comments
I will add some information to this. If you create a scene with
The output is:
Why the 180º rotation? It maybe the cause of the |
It's not a bug per se, there's just no way to uniquely decompose a basis matrix into rotation and scaling when reflection or negative scaling is involved. You can read more about it here for 3D. All the current API guarantees is that the when you query the scale and the rotation, they combine to give you the original basis matrix. I proposed storing rotation and scaling separately which would solve this problem (as opposed to only using a monolithic basis matrix), to solve this problem but it was deemed to be a no-go. One reason in favor of that argument is the current physics engine (bullet, or the old bullet fork labelled "godot") simply doesn't work correctly for bodies with negative scales or reflections anyway, and current bullet wrapper includes a bunch of hacks that makes this assumption. |
I assumed something like this was the reason of this behaviour. That's why I printed rotation too, because I suspected the scale was being transfered to the rotation somehow. I understand why separating both is a no-go, and I think in a similar way. Perhaps the only bug here maybe a lack of documentation, as the user will never be warned about scaling afecting rotating and vice versa (as numerical values shown, not as transformations applied to the object). Thanks for the info! |
After some research myself I understood that indeed is impossible to retrieve the correct scale from the basis matrix when it is negative. Maybe it would just be better to have .global_scale and .global_rotation calculated directly from the stored values instead of using the transform2D? Or maybe we could add separate functions to retrieve the true scale and rotation. Also the documentation should surely be updated for those functions |
I would second DualMatrix's thoughts. It's going to definitely throw a really serious curve ball at any new comers who run into it. I lost much time to my first encounter with it, because I thought the issue was surely in my code. |
I think it would be better if transforms stored scale,rotation and position separately and kept the transform matrix cached and update it when needed. |
Minimal reproduction project from #31980: https://gitlab.com/greenfox/global-rotation-vs-scale |
#21020 describes another symptom of this problem, and has another reproduction project that can be used for testing.
This is not going to happen for many reasons, and I don't think it would actually be an improvement that solves problems. Negative X scales should not be used because they can't be decomposed from the transformation matrix. |
#21849 describes another symptom of this problem, and has another reproduction project that can be used for testing. |
Hello, the following works equivalent to scale.x or scale.y for kinematic bodies with no difference as far as I can tell. So why not add a 'physics flip' property to physics bodies that does this and optionally disable scale, then lots of people won't get confused as much by setting scale and finding it goes all weird and freaky on them?
|
How to rotate characters then? I mean, not just rotating sprite, but raycasts and other nodes too? Reposition one by one& Is there any good solution that I'm missing? |
@chucklepie Your code didn't work for me; I had to modify it to:
where the boolean All of this indirectly sets (And no, that's not a typo. When flipped horizontally, |
this block of code work for me |
Closing this issue as resolved due to documentation improvements. The limitation of negative X scales not working is expected and will not change. The documentation now states the limitations of negative scale #61877. I also proposed adding a warning to let users know about this, but this was decided against: #37376 (comment). When duplicates show up, we should just close them too. Like #21020, #21849, #31980, #42219, #62544, and #62663. |
Thanks, the new note in the documentation was really helpful to understand this. To complete this closure rampage, I also found all the old questions scattered on the Q&A hub related to this and pointed them to this ticket, via one of my answers. I'll also give the link to the most complete answer I gave: https://godotengine.org/qa/92282/why-my-character-scale-keep-changing?show=146969#a146969 because it's filled with alternative ways to flip on X, so useful for people who landed on this ticket in search of a workaround. |
thx! it works for me. future guys, replace |
Version
3.0
Issue description:
When a Node2D has a negative scale in x, global scale will swap the - around to the .y part.
e.g: .scale = Vector2(-2,1) then .global_scale = Vector2(2,-1)
The inverse doesn't happen when y is negative
Steps to reproduce:
Make a scene with a Node2D, give it a negative scale in .x and check the .global_scale.
The text was updated successfully, but these errors were encountered: