I'm extremely new to game creation.

I'm playing around with creating a 2D Unity game. The scene is setup from the default Unity 5 2D template. Following a tutorial, I've created a TerrainManager GameObject and Script. The script instantiates tiles and sets their position using a standard double-loop.

I've found a 2D isometric tile set.
Each tile is visually rendered as rotated around the vertical axis by 45 degrees, creating more of a diamond shape rather than a square. This requires that every second tile be offset by half the tile width on the x-axis, and half the tile height on the y-axis.

As each tile is of a different height, one can not simply offset the tile on the Y axis by half its height. Each terrain "layer" is 16px tall in the PNG. Some PNGs have a single "layer", some have multiple "layers". (For instance, a single layer water tile is 83px in height, while a dual layer "grass on top of dirt" layer is 99px in height.

As the game object expects the transform.position as a Vector3 in (I assume) game units, I do not know how to compose this using pixel values.

So the question I have is, how do I achieve the 16px y-axis offset of the game object?

I'm more than happy to provide additional details if needed.

  • 1
    \$\begingroup\$ What pixels per unit value have you specified in your sprite's Import settings? This will give you the adjustment factor between pixels and world units, if you're using unscaled SpriteRenderers. If you're using UI images in a canvas, then there are a few more details to check. \$\endgroup\$ – DMGregory Sep 11 '16 at 23:21
  • \$\begingroup\$ @DMGregory: Pixels per unit is 100. So I assume that to move 16px I need to add 0.16 to the vector's y-axis? \$\endgroup\$ – Sam Axe Sep 11 '16 at 23:28
  • \$\begingroup\$ @SamAxe Yes, that is correct. \$\endgroup\$ – Draco18s no longer trusts SE Sep 12 '16 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.