-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Godot badly projects 3D camera ray if stretch mode is 2d+"expand" (or "keep") #29614
Comments
Can anyone still reproduce this bug in Godot 3.2.3 rc3 or any later release? If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop. |
I just made a project to reproduce it: And I realize To workaround #29559, and knowing my mouse is locked, I had assumed I could then get the mouse's position from the viewport's center, in final viewport pixels, using this: var mouse_pos = get_viewport().size / 2.0
var ray_origin = _camera.project_ray_origin(mouse_pos)
var ray_direction = _camera.project_ray_normal(mouse_pos) That worked without stretching, but 2D expand mode made it wrong because Otherwise it seems that this issue is fixed. Note: there might be a remaining problem similar to #29559 though. If you start the test project, you'll notice that mouse position will be reported at (0, 0), or sometimes elsewhere, even though it's supposed to be locked at (400, 300), until you start moving the mouse. |
I spent a lot of time trying to figure this out and finally found a solution that worked for me. I still don't completely understand it, but I'll just leave the (C#) code here in case anyone stumbles upon this and wants to try it themselves. Vector2 screenPosition = this.GetViewport().Size / 2;
Vector2 viewportRelativePosition = this.GetViewport().GetFinalTransform().AffineInverse().Xform(screenPosition);
this.Camera.ProjectRayNormal(viewportRelativePosition); If anyone wants to explain and add this to Godot documentation, that would be appreciated. |
Godot 3.1.1
Windows 10 64 bits
I have a 3D game in which I use the following code to get a ray from the captured mouse (itself patched to half the size of viewport because of #29559):
Which works fine with the default stretch mode, even when I resize the window.
However, I have a HUD I want to scale nicely, but if I set the stretch mode to
2d
andexpand
, the 3D ray becomes wrong, offset somehow. I believe camera project functions are broken.Meanwhile, I can't make my UI to stretch properly because of that.
(sorry no time for a repro project yet, I'm in the middle of a game jam)
The text was updated successfully, but these errors were encountered: