Getting screen resolution independent swipe/drag distance

I’m building a very simple basketball game where the player will launch a basketball based on a swipe/drag. I can get the start and end point of the swipe, as well as the time it took to complete. I use distance over time to get the speed and use that value to build a vector to launch the ball.

The problem I have is the following:

On a device with a resolution of 1280x720 the pixel distance of the swipe is different than on a device with a 1920x1080 resolution. On a device with a higher resolution, the player would have to do a much shorter swipe.
What I would like to do is get the screen resolution so I can divide the pixel distance by the screen height. That way it would work the same for any resolution.

So my question is:

  • Is there a way to get the screen resolution at runtime? The Viewport Size node only works in-editor.
  • Is there another or better way to get a resolution independent solution?

One thing I haven’t tried but will give a shot is:

  • Parent a collider to the camera
  • Get the world space coordinates from the screen space location of the begin and end of the swipe
  • Use that distance to do the rest.

I’m guessing that way it would also work on any resolution, but somehow seems a bit hacky?

there are some sort of scale, i cannot find it in google and dont have acess to engine
but, as far as i remember, it should help, type “get scale” into context menu in any widget bp

Yeah both Get Viewport Size and Get Viewport Scale are in-editor only unfortunately :frowning:

I somehow get the feeling that this is way more difficult than it should be.

Sorry but i dont understand what is editor only, packaged build wouldn’t work with those nodes?

Yes, exactly. That’s how I interpret it anyway…


you wrong, i saw this line, have no idea what it means and why it’s there, but half of widget nodes has it.

Yeah you’re absolutely right, just did a little test build on a device and it reads just fine.

Thanks for pointing that out :slight_smile: