Skip to content
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

Scale and rotation bug #48384

Open
RikKargones opened this issue May 2, 2021 · 1 comment
Open

Scale and rotation bug #48384

RikKargones opened this issue May 2, 2021 · 1 comment

Comments

@RikKargones
Copy link

RikKargones commented May 2, 2021

Godot version:
3.3.stable and 3.2.3.stable

OS/device including version:
Windows 7

Issue description:
I want to move any node by Path2D, Pathfollow2D and RemoteTransform2D tandem and change scale manually trough code (of course, I disable rotation and scale update in RemoteTransform2D).

What Expected:
Scale horizontally changes (only -1 and 1) based by x position parameter changes. Scale stay the same if x position not changes. Node moves periodically, backs on start position in loop end.

What Happened:
Node visually changes rotation or scale (fast flips or incorrect flip - bug has variety from scene to scene) and looks like these ((issue 21849) I think it have same roots), but print shows scale parameter sets normally. Rotation prints weird "-0" or Pi (3.14...) after first scale negative set. In code rotation didn't ever used. And move_and_slide function too. If you move node too fast, rotation might sets to 180 degrees after ending moving.

By the way, positive news about these bugs) Looks like KinematicBody2D created in 3.3.stable projects works properly with scaling! But projects created in other versions (3.2.3 or earlier (issue 21849)) unfortunately didn't fixes itself.

I leave separate scene with working negative scaling in attached project filesystem.

Minimal reproduction project:
Test.zip

@RikKargones
Copy link
Author

RikKargones commented May 6, 2021

UPD: I try manipulate with Transform2D node parameter instead scale, like in what tutorial in documentation. It kinda works, finally.

I found these in process: multiplying by negative values sets 0 in Transform2D to "-0". I'm trying to find what may cause such strange behavior in engine source code and I think I find this:

So, in Node2D code scale can't be set by 0. Instead it sets by (I think so) very small variable, like a 0.000000000000000001. It hided from user for preventing write issues like "I set scale by zero, but it isn't a zero!1!!1" or print() just shorting variable to "0" because in function it have a limit for float variables.
изображение
Transform2D is just group of three Vector2-like variables (if simplify) and maybe it's manipulations from near zero values may cause strange behavior after updating values from Node2D changes. I remember rotation returning from Transform2D not as var (because it haven't directly) but as result from atan2 function.
изображение
Maybe function honestly flip node by 180 degrees, because "x" part of Transform2D change to full negative?

You know better, you fix it better, I'm sure)

So, for users what have same problem like mine and if this bug not fixed yet, I leave some code here:

var h_scale = true

func _physics_process(delta):
    if <condition to change scale to left> && !h_scale:
        <Node2D>.transform.x *= -1.0
        h_scale = true
    elif <condition to change scale to right> && h_scale:
        <Node2D>.transform.x *= -1.0
        h_scale = false
                
    if str(<Node2D>.transform.x.x) == "-0": <Node2D>.transform.x.x=0
    if str(<Node2D>.transform.x.y) == "-0": <Node2D>.transform.x.y=0
    if str(<Node2D>.transform.y.x) == "-0": <Node2D>.transform.y.x=0
    if str(<Node2D>.transform.y.y) == "-0": <Node2D>.transform.y.y=0

#<Node2D> - it's any node what you need to change scale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants