-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Camera2D get_camera_screen_center() reports bad position with rotating camera #44358
Comments
With the following project settings: Window Width/Height = (800, 600), Stretch Mode = viewport, Stretch Aspect = keep. I observed the following approximate results from
Note: Screen center values are approximate and are rounded to remove floating point math artifacts, e.g. (50.000061, -0.000061). |
For anyone else who has run into this issue, I found a workaround: var inv_canv_tfm: Transform2D = self.get_canvas_transform().affine_inverse()
var half_screen: Transform2D = Transform2D().translated(get_viewport_rect().size / 2)
var actual_screen_center_pos: Vector2 = inv_canv_tfm * half_screen * Vector2(0, 0)
|
@DragonAxe I tried to adapt your code to my game. But I can currently not multiply a vector with a transform (at least in my C# project). I don't actually understand the third line. Could you explain it so I can adapt? |
Let me see if I can explain, it's been a while since I've looked at this. Basically what I'm doing here is matrix-vector multiplication. Here is a breakdown of my code above:
Hope this helps! |
Thank you for the explaination. I think I now understand it. I adapted the code to C#:
I tested if this works with my implemented camera shake. But I guess there is a problem left with the offset (as you mentioned already), because the position seems to be off when my camera shakes. But maybe I can find a way to fix this. :) |
I had accidentally made a duplicate of this. Reposting as a comment here in case my repro might be useful. Godot versionv4.2.beta.custom_build [b137180], v4.1.2.stable System informationGodot v4.2.beta (b137180) - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce GTX 1080 Ti (NVIDIA; 31.0.15.3623) - AMD Ryzen Threadripper 1950X 16-Core Processor (32 Threads) Issue descriptionThe Vector2 returned by Steps to reproduce
Minimal reproduction projectIn this example project there are two scenes with similar setups. one_cam.tscn is from the perspective of the rotating camera. |
I've looked at #63773 and it will unfortunately NOT close this issue, though I don't believe it was intended to. I agree that if that gets merged, it will at least make it easier to fix this issue. |
In C# default constructor zeroes the structs. In GDScript Anyway, pure translation transform can be omitted by straight up adding the translation to the vector, same effect: Transform2D inverseCanvasTransform = this.GetCanvasTransform().AffineInverse();
Vector2 actualScreenCenterPosition = inverseCanvasTransform.Xform(this.GetViewportRect().Size * 0.5f); |
Godot version:
Godot Engine v3.2.3.stable.official
OS/device including version:
Arch Linux 5.9.11-arch2-1 #1 SMP PREEMPT Sat, 28 Nov 2020 02:07:22 +0000 x86_64 GNU/Linux
OpenGL ES 3.0 Renderer: Mesa Intel(R) UHD Graphics 620 (KBL GT2)
Issue description:
What happened: Camera2D method
get_camera_screen_center()
does not return(0, 0)
when the camera is being rotated withself.rotate(0.1*delta)
,Offset=(0, 0)
,Current=On
,Rotating=On
, andAnchor Mode = Drag Center
.Note: With
Anchor Mode = Fixed TopLeft
I also see unexpected behavior where the position reported byget_camera_screen_center()
remains unchanged even though the camera view is rotating about the top left corner.What I expected:
get_camera_screen_center()
should continue to return(0, 0)
at any rotation angle as long as Offset=(0, 0) and the Anchor Mode = Drag Center.Note: With
Anchor Mode = Fixed TopLeft
the position reported byget_camera_screen_center()
should follow a circular path with center at the top left corner of the camera and radius equal to half the diagonal length of the camera window size.https://docs.godotengine.org/en/stable/classes/class_camera2d.html#class-camera2d-method-get-camera-screen-center
Steps to reproduce:
get_camera_screen_center()
.)Anchor Mode: Drag Center
Rotating: On
Current: On
You should see the label in the center of the screen rotating while displaying the output of
get_camera_screen_center()
.Minimal reproduction project:
bug_cam_screen_center.zip
The text was updated successfully, but these errors were encountered: