In my game, I need to get the hexagon that is underneath the mouse. This worked fine before I added a camera system to allow me to have bigger hexagon grids that go off-screen. If I move the camera, it starts acting weird and not getting the correct hexagon.
I've tried subtracting the camera position (defined as cam.x and cam.y) from the mouse position, subtracting mouse position from cam position. Obviously, I have little idea of what I'm supposed to actually do in this situation.
You can see the relevant code below.
if button==3 then
local hovering=hexGrid:containingHex(x,y) -- get hexagon at mouse position onclick
if hovering then
local data=hexes.getHexagon(hovering)
data["text"]=data["text"]=="1" and "2" or "1"
end
end