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

InputEventMouseMotion.Relative is tied to window size #49734

Closed
swift502 opened this issue Jun 19, 2021 · 5 comments · May be fixed by #57264
Closed

InputEventMouseMotion.Relative is tied to window size #49734

swift502 opened this issue Jun 19, 2021 · 5 comments · May be fixed by #57264

Comments

@swift502
Copy link

swift502 commented Jun 19, 2021

Godot version

v3.3.2.stable.mono.official

System information

Windows 10, GLES3, GTX 1060 3GB 27.21.14.6647

Issue description

I noticed that running my game in windowed mode at 1920x1080 results in noticeably higher mouse sensitivity than running it at 2560x1440.

Turns out the Third Person Shooter Demo suffers from the same issue. I performed roughly the same mouse movements with two different window sizes.

Left: 320x240 window, produces ~360° of camera rotation
Right: 2560x1440 window, produces ~60° of camera rotation

comparison.mp4
  • Is this intended behavior?
  • Is it not a problem to essentially have mouse sensitivity tied to screen resolution?

Thanks.

Apparent solution

In case it helps, I noticed that multiplying the relative value by the smaller window dimension results in what I percieve as the "correct" behavior, where sensitivity remains constant across different window sizes and aspect ratios.

RotateCamera(@event.Relative); // works poorly

RotateCamera(@event.Relative * Mathf.Min(OS.WindowSize.x, OS.WindowSize.y)); // works much better

Steps to reproduce

  1. Use InputEventMouseMotion.Relative to orbit your camera around.
  2. Run the game in windowed mode
  3. Test mouse sensitivity with different window sizes
  4. Test exaggerated aspect ratios, like and extremely wide or tall window, as the incorrect mouse sensitivty becomes even more apparent at those sizes

Minimal reproduction project

Third Person Shooter Demo

@Calinou
Copy link
Member

Calinou commented Jun 19, 2021

Is this intended behavior?

I don't know if this is intended behavior, but I think relative mouse motion in captured mouse mode should be resolution-independent, regardless of the stretch mode configured. This is how it works in most games after all.

As far as I know, this depends on the configured stretch mode in the Project Settings. Compare the default disabled mode with the 2d stretch mode, then compare it with the viewport stretch mode.

Changing this will require breaking compatibility with existing projects, so it can only be done for 4.0.

@swift502
Copy link
Author

this depends on the configured stretch mode

You seem to be right.

  • disabled seems to work correctly.
  • 2d behaves incorrectly (as seen in the "comparison" video I posted).
  • viewport seems to behave roughly the same way as 2d, also incorrectly.

@flouterrr
Copy link

flouterrr commented Nov 7, 2021

I'm still not 100% sure since I haven't looked at the engine code, but I suspected that InputEventMouseMotion.relative is actually tied to the size of the viewport / project width & height.

So after some testing I found that the solution is multiplying the InputEventMouseMotion.relative vector by a ratio of the size of the smaller window side by the corresponding size of the viewport side. That's one hell of a sentence, I'll post the code so that I'll hopefully make more sense.

var mouse_movement : Vector2
	if min(OS.window_size.x, OS.window_size.y) == OS.window_size.x:
		mouse_movement = event.relative * (OS.window_size.x / get_viewport().size.x)
	else:
		mouse_movement = event.relative * (OS.window_size.y / get_viewport().size.y)

I don't know how efficient (or iefficient) it is to have this if else statement run time there is any mouse movement, but it does work, so if anyone has any ideas on how to make this more optimized then the coast's clear.

@Braboware
Copy link

I recorded some data in 4.1.1 that may be useful.
Project used for testing
used https://github.com/KovaaK/SensitivityMatcher for windows
and https://github.com/grindzohr/SensMatch for linux
3.0 sens x 0.022 yaw

OS Viewport Width Viewport Height Size Mode Stretch Mode   rotation_degrees.y, 1 Rotation rotation_degrees.y, 22 Rotations Notes
Windows 11 2560 (native) 1440 (native) Windowed disabled   -0.0299999062 0.0000409813365 On target
Windows 11 2560 (native) 1440 (native) Windowed canvas_item   -4.809093475 -106.6027145  
Windows 11 2560 (native) 1440 (native) Windowed viewport   -4.875981808 -106.6026764  
Windows 11 2560 (native) 1440 (native) Fullscreen disabled   0.03600022942 0.00001451422577 On target
Windows 11 2560 (native) 1440 (native) Fullscreen canvas_item   -0.593421638 -12.39433098  
Windows 11 2560 (native) 1440 (native) Fullscreen viewport   -0.5273184776 -12.39431095  
Windows 11 2560 (native) 1440 (native) Exclusive Fullscreen disabled   0.03600022942 0.0000589106312 On target
Windows 11 2560 (native) 1440 (native) Exclusive Fullscreen canvas_item   -0.0299999062 0.00002646711255 On target
Windows 11 2560 (native) 1440 (native) Exclusive Fullscreen viewport   0.03600022942 0.00006061821477 On target
Windows 11 640 480 Windowed disabled   0.03600022942 0.0000409813365 On target
Windows 11 640 480 Windowed canvas_item   -0.0299999062 0.00005549551497 On target
Windows 11 640 480 Windowed viewport   0.03600022942 0.00002646712164 On target
Windows 11 640 480 Fullscreen disabled   -0.0299999062 0.00005549550406 On target
Windows 11 640 480 Fullscreen canvas_item   -120.1757736 -124.1312561  
Windows 11 640 480 Fullscreen viewport   -120.1978073 -124.1312714  
Windows 11 640 480 Exclusive Fullscreen disabled   0.03600022942 0.00001451422577 On target
Windows 11 640 480 Exclusive Fullscreen canvas_item   -120.0100021 -120.0000763  
Windows 11 640 480 Exclusive Fullscreen viewport   -120.0100021 -120.0000992  
                 
Kubuntu 23.04 2560 (native) 1440 (native) Windowed disabled   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 2560 (native) 1440 (native) Windowed canvas_item   -22.75618935 -140.6360779  
Kubuntu 23.04 2560 (native) 1440 (native) Windowed viewport   -22.75619316 -140.6360016  
Kubuntu 23.04 2560 (native) 1440 (native) Fullscreen disabled   -0.02998282574 -0.6598005891 On target
Kubuntu 23.04 2560 (native) 1440 (native) Fullscreen canvas_item   -0.02998624183 0.6597261429 On target
Kubuntu 23.04 2560 (native) 1440 (native) Fullscreen viewport   -0.02999136411 -0.659752965 On target
Kubuntu 23.04 2560 (native) 1440 (native) Exclusive Fullscreen disabled   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 2560 (native) 1440 (native) Exclusive Fullscreen canvas_item   -0.0299999062 -0.659974277 On target
Kubuntu 23.04 2560 (native) 1440 (native) Exclusive Fullscreen viewport   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 640 480 Windowed disabled   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 640 480 Windowed canvas_item   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 640 480 Windowed viewport   -0.0299999062 -0.6599736214 On target
Kubuntu 23.04 640 480 Fullscreen disabled   -0.0299999062 0.6599736214 On target
Kubuntu 23.04 640 480 Fullscreen canvas_item   -120.0100021 -120.2200623  
Kubuntu 23.04 640 480 Fullscreen viewport   -120.0319977 -120.2200623  
Kubuntu 23.04 640 480 Exclusive Fullscreen disabled   0.0299999062 -0.6599713564 On target
Kubuntu 23.04 640 480 Exclusive Fullscreen canvas_item   -120.0100021 -120.2200623  
Kubuntu 23.04 640 480 Exclusive Fullscreen viewport   -120.0100021 -120.2200623  

@Calinou
Copy link
Member

Calinou commented Oct 4, 2023

Thanks for the report! Consolidating in #34805, as this is due to the same cause.

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

Successfully merging a pull request may close this issue.

4 participants