1
\$\begingroup\$

I created a test project to see how different mobile resolutions affects Unity's 2D Physics.

They way I handled the resolutions was to contain all the objects (including non-UI objects) in a Canvas and use a Canvas Scaler component to adjust for multiple resolutions. Although this approach is probably not one of the ways the Canvas was not meant to be used, it works well when working with a single orientation.

Despite the quick solution to handle the multiple resolutions, there seems to be the issue of the physics acting differently depending on what aspect ratio is being used.

Images can be viewed here: https://i.stack.imgur.com/mszoX.jpg

The green and blue blocks both have the Rigidbody2D and Box Collider 2D components. The floor (big white block) only has a Box Collider 2D component.

As you can see from the images above, the different aspect ratios cause the blocks to collide with the floor at different times. Also, when using rigidbody.addforce in the Y direction, the different aspect ratios cause the blocks to jump at different heights.

Obviously these issues could cause an unfair advantage in a game with support for several resolutions.

So how would I go about adjusting the physics so that the blocks fall and jump at the same rates relative to the different resolutions?

Also if there is a more practical way to adjust for multiple resolutions that doesn't involve a plugin and doesn't break physics, let me know!

\$\endgroup\$
9
  • 1
    \$\begingroup\$ The "images" link shows only a single image, which doesn't illustrate the different collision times you describe. In any case, trying to adjust physics is likely to be a massive headache with questionable reliability. You'll likely have better results changing your camera to suit the resolution, and keeping your gameplay at a known constant scale. \$\endgroup\$
    – DMGregory
    Feb 25, 2016 at 2:38
  • \$\begingroup\$ You are doing it wrong. If you're doing this just to make your game adapt to different resolutions, there are easier,simpler and better ways of doing that. \$\endgroup\$
    – SanSolo
    Feb 25, 2016 at 5:57
  • \$\begingroup\$ @DMGregory Thanks for the feedback. As I said, this was just a test to see how the 2D physics would react to multiple resolutions when the objects are scaled. I figured the canvas scaler would cause some problems, as it was too easy to adjust to most resolutions. \$\endgroup\$
    – Alkhzar
    Feb 25, 2016 at 18:15
  • \$\begingroup\$ @SanSolo Thanks you, but I wasn't aware there was a right or wrong way. The quick 'n' easy method I used was most likely impractical but my post implied this. Also I'm not doing this for a game of mine, I was following along an android tutorial that didn't involve Unity. I figured it would be good practice to see if I could replicate the program using Unity. I tried to use a simple solution, but I quickly realized that it really wasn't the simple solution. \$\endgroup\$
    – Alkhzar
    Feb 25, 2016 at 18:26
  • 1
    \$\begingroup\$ Excellent! Are you going to write up your solution as an answer so readers coming later can benefit from your experience? \$\endgroup\$
    – DMGregory
    Feb 25, 2016 at 20:57

1 Answer 1

1
\$\begingroup\$

Instead of using the canvas scaler as a solution, I went the route of DMGregory's suggestion and ended up finding this blog by Adrian Lopez that worked perfectly for my needs.

It turns out that using the canvas scaler to adjust gameobjects with physics components can impact the way gameobjects respond to the physics engine when changing from one aspect ratio to another. This approach would require fine tuning of the physics components' members to create consistent physics across all aspect ratios. Clearly, this is counterproductive to my original idea of a simple aspect ratio adjuster. This revelation and DMGregory's suggestion helped me decide to use another approach.

For the new approach, I went about researching different ways to adjust the camera and came upon the blog I linked earlier in my answer. What this approach does is re-size the camera according to the current screen height and width to add a letterbox or pillarbox effect in order to keep consistency across multiple resolutions. A bonus is that this approach does not alter the physics when changing to different aspect ratios.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .