• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML (Math Problem) Isometric Coordinate Conversion

E

Ephemeral

Guest
How do you convert from room coords to iso coords? I'm having a brain failure.

To convert from iso coords to room coords is straightforward:
Code:
x = (iso_x * TILE) - (iso_y * TILE);
y = (iso_y * TILE * 0.5) + (iso_x * TILE * 0.5);
But I'm blanking on how to do the reverse operation. It seems like it should be straightforward, but...
 
G

Geniusbat

Guest
My highschool math skills are saying this should be:
iso X coordenate = (x/ tile) - (y/tile);
iso Y coordenate = (y/tile/0.5) - (x/tile/0.5);
Do not know if it is wrong or right, I just reversed everything from your code, I hope at least it gave you some inspiration.
Good luck!
 

JackTurbo

Member
Code:
LocalX = ((GlobalY - IsoY) / IsoH + (GlobalX - IsoX) / IsoW) / 2;
LocalY = ((GlobalY - IsoY) / IsoH - (GlobalX - IsoX) / IsoW) / 2;
IsoW and IsoH are the ratio of the tiles height to width, so that would be 2 and 1 for normal 2:1 ratio.
GlobalX/GlobalY are the isometrically projected coords that you want to translate to 2D.
IsoX/IsoY are the starting coords of the grid. (incase you have an offset to center the grid in the room or whatever).

@YellowAfterlife has a great write up on his blog about this (which this is lifted from) here: https://yal.cc/understanding-isometric-grids/
He also has an example project that might be useful to download and explore how he has approached things. - I know it was a bit of a lightbulb moment for me when I did last year.


Clint Bellanger also has a great write up of isometric projection (although not GMS focused, the maths stuff is universal) here: http://clintbellanger.net/articles/isometric_math/

Those two links should give you 99% of what you need to work successfully with isometric projection.
 
Last edited:
given the isometric to room conversion you proveded, then to reverse it is:

X = (y + x/2)/T;
Y = (y - x/2)/T;

(X,Y) = isometric position
(x,y) = room position
T = TILE
 
Last edited:
Top