mastodon.gamedev.place is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server focused on game development and related topics.

Server stats:

5.4K
active users

I'm too tired for my historians mind to try to find out how to calculate the tile coordinate on my map for any given mouse position. 64 by 64 pixels but it's not a square but a diamond, so about half of the 64x64 box in all four corners is not this tile and they're not even arranged neatly. Anyone with a solution?

@TommyvanSon maybe something about rotating your input 45 degree then pretending your grid is horizontal with that input

Or if you're in Godot/unity/similar you can have the square have a matching mouse listener with its grid coord without worrying about screen coords

Tommy van Son ✔

@ScruffyBrush i was trying that earlier in the process, I think, but I feel like that makes the other way around calculation trickier (find the position based on the coordinate). And then the grid will have even more inequal lines. I'm very hesitant to take this approach. Thanks though!😊

@TommyvanSon
Another way that might be simpler math wise is

For a square
AB
CD
Consider each of your diagonal separation between tiles as a linear function
(the ones that are aligned with AD and the ones with CB)

To identify which square or empty space you clicked, find the lowest function that is higher or equal to clicked poison input

@ScruffyBrush thank you. I found the solution with the help of another suggestion but your help was appreciated too!