Pixel-perfect panning for an orthographic camera on RMB, 2D, no character

I’m having trouble implementing pixel-perfect panning for an orthographic camera in a 2D game (no character). Basically, I need Google Maps style controls.

Also, I change the OrthoWidth for zoom using the mouse scroll wheel, so I need to account for that.

UE 5.7

I discovered that an OrthoWidth of 1080(camera settings) perfectly matches the mouse position with the scene while panning. So I get the current OrthoWidth and divide it by 1080(base value for perfect match) to scale the mouse movement. It works perfectly when the window width is ≥ 1080 in standalone mode. However, when I reduce the window width to something smaller than 1080, the panning starts to desynchronize. I suspect this might be related to my hardcoded OrthoWidth division or the DPI Scale curve (because 1080 is 1 there). I don’t want to disable DPI scaling ofc, and even if I do, it breaks again. What am I missing?

Here’s the main nodes:

Hey @s0up how are you??

The problem here is the hardcoded “1080”, just as you suspected!

To make it work for any resolution, you should only change that harcoded number by the following formula:

You full blueprint should look something like this:

Let me know if this worked! Or if we need to polish it a little bit more!

1 Like

Hey, I’m good, thanks!

I tried that formula, but it didn’t match the mouse position with the point where panning started in the scene, but if you divide the height(Y instead of X), it works!

I actually figured it out myself a couple of days ago, it’s a bit different, but works perfectly:

I figured that GetMousePositionOnViewport applies unnecessary DPI scaling, and the PlayerController→GetMousePosition is a few frames behind the actual mouse position or something, causing latency. But GetMousePositionOnPlatform is perfect for me, it’s absolute XY on the screen.

Thank you for answering, I didn’t expect anyone to respond at this point.

1 Like