   Hexagonal tilemap collision with variable heights
  Greetings, fellow GameDev members.Rendering a hexagonal tilemap is not very difficult, but checking which tile the mouse is over is a bit harder (since the tiles overlap). This was what I was trying to do, and then I found the solution in an article here at GameDev. You simply have an off screen color map which you place your mouse on to see what tile it is on, *link to the article*. But that solution isn't enough for my map, which uses different heights for different tiles. Here is a screenshot of my map.Using the color map technique won't work on the elevated tiles, since it would be completely misplaced relatively to the other tiles. Then there's another problem; my map has some small spacing between the tiles, but that is probably a trivial issue. Fortunately though, I only have 5 height levels: low, lowered, normal, raised and high. What are my options? What technique would I use to determine the mouse's position on the tilemap?Any help is greatly appreciated!Martin[Edited by - Heptagonal on September 9, 2007 1:01:57 PM]
  Exhaustive enumeration would be the fastest and easiest. You only have to check a dozen tiles (above and below the click point, in the two columns corresponding to it) starting with the lowest, until you find one which contains the mouse position.   ;  I don't understand what you mean. However, I think I found another solution. If I simply extend the color map method and have 5 different maps - one for each height - it would probably work. What do you think?   ;  I don't think it will workActually, what I'll do (well it's just the first idea I came up) it's to do the "color algorithm" and then check the hex under the selected to see if it has oberlapped the selected. Then I'll need to check the selected one for the case it were "down" and you're current selecting background.A silly question... if you have a tile at high height and anoder at low and they overlap... how do you select the one hidden?   ;That never happens.But I think that your method might work, I'll try it out. First you ignore all the heights and calculate the mouse position with the color technique, then if the tile is elevated, you do the color test again but this time at the same position as the elevated tile to see if the mouse fits into both of the color maps. Was that what you meant?   ;  With some clever help from a friend, I think I have the solution to the problem. I'll try it out, and tell you if it the method is a success.   ;  If you can figure out where to draw the tiles on the screen, and you know where the mouse pointer is then its simple algebra to figure out which tile the mouse is over. You don't need offscreen color maps and all those resource intensive solutions.   ;  For anyone who is interested, I'll make a quick explanation of how I solved the problem.I simply looped through all the tiles, sorted after height. First it looped through all of the tiles at the top, and checked if the mouse was there. If not, it moved down one step, and then repeated the process. Then I took the easy way out only using a rectangle for collision detection at the middle of the hexagon, ignoring the top- and bottommost parts of it.   ;Original post by HeptagonalI simply looped through all the tiles, sorted after height. First it looped through all of the tiles at the top, and checked if the mouse was there. You know the x-pos of the cursor, so you can restrict yourself to two columns only.;  Ah, you're right -- I feel really stupid now! [smile]   