@jakob.pogulis Yeah, I know
I was at it!
The problem was in this code below:
for y = 0, 2, 1 do
pos.y = 80 + blocksize * y
self.board[y] = {}
for zero = 3-(y+1), 1, -1 do
posish = posish + 80
apos = apos + 1
end
for x = 0, 2*(y+1)-2 do
pos.x = 80 + blocksize * x + posish
pos.z = x * -0.1 + y * 0.01
c = stones[math.random(#stones)]
local id = factory.create("#blockfactory", pos, null, { color = c })
apos = apos + x
self.board[y][x] = { id = id, color = c, y = y, x = apos }
end
posish = 0
apos = 0
end
If to be precise in this part of it, where you assigning “x” and “y” to the table:
apos = apos + x
self.board[y][x] = { id = id, color = c, y = y, x = apos }
Let’s imagine this situation: In the first pass of the “X” loop -> x = 0 and when we try to map the values to the table it looks like that:
- but apos here is 2, which is why the actual image of the block was located correctly (X = 2), BUT it’s “hitbox” was at X = 0.
All that we have to do here is to map the position we want. So, here’s the final correct code:
for y = 0, 2, 1 do
pos.y = 80 + blocksize * y
self.board[y] = {}
for zero = 3-(y+1), 1, -1 do
posish = posish + 80
apos = apos + 1
end
for x = 0, 2*(y+1)-2 do
pos.x = 80 + blocksize * x + posish
pos.z = x * -0.1 + y * 0.01
c = stones[math.random(#stones)]
local id = factory.create("#blockfactory", pos, null, { color = c })
x = x + apos -- In the first pass x is 0, then -> x = 0 + 2;
self.board[y][x] = { id = id, color = c, y = y, x = x } -- self.board[0][2] = { id = id, color = c, y = 0, x = 2 }
-- Now it is correct
end
posish = 0
apos = 0
end