0
\$\begingroup\$

new to game development and unity so hopefully someone can help.

I want to make a 2D portrait mobile game that will have a grid of constant size where units can move on in Unity.

This should support different aspect ratios. To do that I was thinking to cut sections at the top and bottom of the screen for smaller aspect ratios.

Additionally, I would like the coordinate system to be natural to the grid, so coordinate (0,0) would be the bottom left tile in the grid, (1,0) would be the tile to the right of that,... To illustrate this concept I drew something quickly:

grid sample

I tried with a script that resizes the size of the orthographic camera to fit the content horizontally. Problem I had with that is that I couldn't get a good coordinate system on the grid after the camera gets resized depending on the aspect ratio since the number of horizontal world units varies depending on the aspect ratio.

Any thoughts on what would be the best way to do this? Thanks!

\$\endgroup\$
3
  • \$\begingroup\$ It sounds like you picked the wrong camera sizing script, or configured it incorrectly. Show us what you used, and we can help you fix it. We have existing, tested and working solutions here and here too - how have you tried applying them to your case? \$\endgroup\$
    – DMGregory
    Mar 26 '20 at 10:33
  • \$\begingroup\$ Agh right, my camera sizing script was wrong... I was doing camera.orthographicSize = targetHorizontalSize * Screen.height/Screen.width * 0.5f which I got from pressstart.vip/tutorials/2018/06/13/37/…. I used the first link you posted and it works perfectly. Thank you so much for your help! if you post this as an answer I can mark it as the correct answer. \$\endgroup\$
    – Tonidero
    Mar 26 '20 at 16:38
  • \$\begingroup\$ I'm glad you solved it! Next time, be sure to search for existing Q&A before posting a new question, so you can find working answers even faster. \$\endgroup\$
    – DMGregory
    Mar 26 '20 at 16:56