-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Problem with get_global_mouse_position in multiple Viewports #31551
Comments
Definitely sounds like #31551 -- it is the same issue after all.. |
Omg ;_; |
Oh wow, I totally overlooked these Issues and yeah I'm pretty sure they are related to mine ... sorry. Anyway if anyone stumbles upon the same problem as I(and to make this issue here at least a bit useful), I found a workaround that's works with window scaling etc. I simply calculate the mouse position by myself. Here is the function that I have created for this:
If you want to give this a go, you can simple place this function inside the "LookAtMouse.gd" that I've provided in the "Minimal reproduction project" and use this one instead of the "get_global_mouse_position". After that, it shouldn't be to hard to adapt these codelines to your own project. Hope this helps someone Edit: Actually I found out that the way I calculate the mouse position was indeed incorrect(but only slightly so I didn't noticed) and also doesn't work with camera zoom and borders. So after a lot of trying, I've finally found a solution that should work every time (no guarantee off course ^^). Anyway I've update the code above |
So yeah, this really is about viewports and stretch mode, so closing it as a duplicate of #30950 |
Godot version:
3.1.1 - Stable
OS/device including version:
Windows 10-64 Bit
Issue description:
Hello,
I'm currently trying to implement split-screen in my game and after watching some tutorials I decided to gave this a go. At first everything seems to work fine, but then I stumbled upon the problem, that my topdown-character doesn't want to "look" at the mouse-position anymore. After some more investigation I found out, that the problem seems related to the Stretch-Mode that I have defined(currently "2D" and "keep" for the aspect) because the "lookat" function seemed to kinda work when I maximize the window but not, as soon as I start walking away from the origin with my player.
The code/function I use to let the player look at the mouse is basically just this:
With that everything worked fine, as long as I've got only one player (actually the other player is controlled with an PS4-Controller and only one player is using the PC-Inputs), but with two or more it's basically impossible to aim at anything. Since I have no clue now how to fix this, I decided to create this Issue even though this might not be a bug at all and I just used the wrong function(maybe the get_global_mouse_position isn't just the right function to use in this case even though I expected to take this kind of stuff into account and always give me the correct global position). Regardless of this, it would be pretty nice if someone could help me out with this (basically all I want in relation to the minimal reproduction project is, that the red and blue sprites are aware of the split-screen and depending in which viewport the mouse currently is, the red or blue sprite should perfectly look at the mouse position).
I hope it was understandable what I mean and I'm looking forward for any help ^^
Steps to reproduce:
I think the easiest way is to just look at the example project I've provided
Minimal reproduction project:
Multiple_Viewports_Bug.zip
The text was updated successfully, but these errors were encountered: