0
\$\begingroup\$

I have code that calculates where the user clicked inside an iso tile in an isometric map. The tile has a width of 1 unit and a height of 0.5 units. My code calculates where they touched inside the tile in these same units. The goal is to then decide where that click falls if you sub-divided the iso tile into a 4x4 grid. The picture below shows how all this is supposed to look.

enter image description here

I have found ascreen co-ordinates to iso formula and it makes sense but for whatever reason, when I try to use it with my data above I get wrong outputs. When clicking from the top corner to the right corner, only the X iso output should change but both the X and the Y change.

I feel like this should be pretty simple but after hours of banging my head against this I can't figure out what I am doing wrong.

Source for screen to iso formula: How would I translate screen coordinates to Isometric coordinates?

Any help would be greatly appreciated.

float touchedX;
float touchedY;
//below 0.125 represents the tile height because the whole thing
// is 0.5 and its 4 tiles high so 0.125, 0.5 is 2*width which 
//is (1 / 4.0) * 2
float gridPointLedftDown = (touchedY / 0.125f) + (touchedX / 0.5f);
float gridPointRightDown = (touchedY / 0.125f) - (touchedX / 0.5f);
\$\endgroup\$
2
  • \$\begingroup\$ hint: when you have both iso-coordinates and screen-coordinates in the same project, calling both x and y can become quite confusing. In one project where I used iso-coordinates I used the convention to call the axis' of the iso-coordinate system l and r (for left-down and right-down) instead. That really helped me a lot to keep my code understandable. \$\endgroup\$
    – Philipp
    Commented Feb 7, 2017 at 10:29
  • \$\begingroup\$ Updated the code to reflect that. \$\endgroup\$ Commented Feb 7, 2017 at 15:28

1 Answer 1

1
\$\begingroup\$

It looks like the formula I had from that other site was just wrong. IsoY should be calculated as y / tileHeight - x/ tileWidth. The *2 on tileWidth when removed made the values come out correctly.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .