2
\$\begingroup\$

The Tilemap object in Unity uses a coordinate system that grows up-right from (0,0). (ie. with the Origin at the bottom-left of the screen.) I'm trying to represent a mapping system that has the origin at the top-left of the screen and grows down-right instead, but I can't figure out how to do it.

Scaling the tilemap's Y transform by -1 draws everything upside-down. Trying to set the object's Tilemap component to custom orientation and setting its Y scale to -1 appears to have no effect, and the editor doesn't accept it anyway, changing what I entered, setting the Y scale back to 1 and the X scale to -1 instead.

Is there any way to fix the Tilemap so that everything draws like normal, except for Y growing downward instead of upward?

\$\endgroup\$
3
\$\begingroup\$

It might be smarter to work with unity instead of against it and just accept how its coordinate system works. Keep in mind that this coordinate system follows the same "y is up" logic as the Unity world-space coordinate system, so this is just consistent.

But if you really want to do this, then one option would be to write a couple of extension methods for the Tilemap class which just call the standard methods but with the y-coordinate inverted.

You could also create a completely new class (plain old C# class, not a MonoBehaviour) which works as an adapter for a tilemap. It would have a private Tilemap tilemap and a bunch of public methods and properties which call methods / access properties of the wrapped Tilemap object. If you only access your tilemap through this adapter class then you don't need to worry about accidentally mixing your API with the standard API and getting unexpected results.

Unity tilemaps can grow into negative coordinates, so the origin doesn't necessarily need to be in the bottom left. You can also put the origin in the upper left and use increasing negative y-coordinates. So the tile 3 to the right and 5 to the bottom has the coordinates 3 : -5.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Using negative Y coordinates worked. I don't like it, because I had to move the camera and that involved a bunch of other stuff moving around... but it worked. \$\endgroup\$ – Mason Wheeler Apr 9 '19 at 10:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.