# [SOLVED] About Translate & scale the level canvas

Hello. I cannot finish to understand WHY are we scaling downto 0.0075 in X and Y the Level canvas.
And also WHy are we divinding by 2 when we adjust the grass tile
I am really not brilliant in math

If someone can explain this i would realle appreciate it.

2 Likes

I believe we divide by two because there are 2 grass squares per tile. The level canvas has been set up with one pixel per world unity. But we want to change this to be only 12 world units wide. Thatâ€™s why we multiply by 12/1600.

@sampatuzzi is right, Iâ€™ll elaborate the steps which brings us to the 0.0075 scale for the canvas.

We have a canvas which is 1600x900 pixels and letâ€™s say that we choose the origin of the axis to be the center of this canvas.

This means that the center will have a transform position (from here on, Iâ€™ll call it just position) of (0,0). If I want to put a game object in this center, Iâ€™ll have to assign it a position of (0,0), if I want to put an object in the upper right corner of the canvas, Iâ€™ll have to assign it a position of (800,450) and so on.

We could manage the whole game just using these coordinates, unscaled (or rather, with a scale of 1 in both X and Y directions).

But, is it really the best solution? Considering that we need to consider the grass squares as the world units, itâ€™s not the best really. What we want is a new way of representing coordinates of game objects which is easier to understand, relative to the game requirements.

Considering this, we already know that on a 16:9 screen, and with a resolution of 1600x900, we need a total of 12x6.75 squares.

In order to do this, we need to â€śtranslateâ€ť from one set of coordinates (pixels) to another set of coordinates (world units), so that the position coordinates of game objects represents world units and not pixels.

So, letâ€™s go back to the center of our canvas. Since itâ€™s the origin of the axis, we are setting there the (0,0) position coordinates, and this is true in both measuring scales (pixels AND world units). What about, though, the center of the square immediately on the right? Of course the Y coordinate will be still 0, but what about the X coordinate?

If we stay on the original system, we know that, since there are 12 squares total per 1600 pixels, a single square is 1600/12 = 133.3333â€¦ wide, so the center of this square is (133.3333,0), if expressed in pixels.
But to work in world units coordinates system, we know (cause we decided it) that the position of the center must be (1,0), i.e.: 1 square to the right of the center square.

So, in the end, how can we â€śshrinkâ€ť a shift of 133.3333 pixels to the right to be represented by the number 1? Simple: we divide 1/133.3333 = 0.0075. And can we manage to apply this scaling of coordinates to all the game space? By scaling down the original canvas to a scale of 0.0075.

Thatâ€™s why, when you put an object in the center of the square on the right of the central one, that object will have a position in Unity of (1,0) instead of (133.3333,0). If you try to put the canvas back to a scale of 1, and you put an object there, youâ€™ll see that Unity will show a position of (133.3333,0).

Sorry for the lengthy post, but I wanted to explain this coordinates conversion step by step. Hope this helped to understand the process!

7 Likes

Exellent explanation @Galandil. Thank you very much. Also thank you @sampattuzzi.

I really appreciate the help. Thanks