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?