Mouse Position to Isometric to Tiles?
Posted: Sun Mar 30, 2025 7:52 am
Hello!,
I have been following this video (https://www.youtube.com/watch?v=04oQ2jOUjkU&t=181s) trying to make an isometric map. Everything is working fine. However, I do not understand how to get the mouse mx and my to translate into a selected tile
.
This is what i have so far for the code. It is the direct inverse. I this the best way to do this? Should i look up how to do ray-cast things or is this cool?
local function tileToCartt(mx,my)
local a = ((1 / 2) * widthSprite)
local b = ((-1 / 2) * widthSprite)
local c = ((0.5 / 2) * heightSprite)
local d = ((0.5 / 2) * heightSprite)
local inv = 1 / (a * d - b * c)
local invA = inv * a
local invB = -(inv * b)
local invC = -(inv * c)
local invD = inv * d
--[[
A = [a, b c, d]
Ainv = 1/ad - bc * [d -b c a]
local i1 = a * invD + b * invC
local i2 = a * invB + b * invA
local i3 = c * invD + d * invC
local i4 = c * invB + d * invA
print('i1= ' ..i1..'i2= '..i2..'i3= '..i3..'i4= '..i4)
]]
local w = invD * my + invB * my
local b = invC * mx + invA * mx
return w,b
end
I have been following this video (https://www.youtube.com/watch?v=04oQ2jOUjkU&t=181s) trying to make an isometric map. Everything is working fine. However, I do not understand how to get the mouse mx and my to translate into a selected tile

This is what i have so far for the code. It is the direct inverse. I this the best way to do this? Should i look up how to do ray-cast things or is this cool?
local function tileToCartt(mx,my)
local a = ((1 / 2) * widthSprite)
local b = ((-1 / 2) * widthSprite)
local c = ((0.5 / 2) * heightSprite)
local d = ((0.5 / 2) * heightSprite)
local inv = 1 / (a * d - b * c)
local invA = inv * a
local invB = -(inv * b)
local invC = -(inv * c)
local invD = inv * d
--[[
A = [a, b c, d]
Ainv = 1/ad - bc * [d -b c a]
local i1 = a * invD + b * invC
local i2 = a * invB + b * invA
local i3 = c * invD + d * invC
local i4 = c * invB + d * invA
print('i1= ' ..i1..'i2= '..i2..'i3= '..i3..'i4= '..i4)
]]
local w = invD * my + invB * my
local b = invC * mx + invA * mx
return w,b
end