You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Make a grid for my game for a pool of pee
-
What is the issue? When the make grid function is exited the coordinates change…? I have no idea what’s happening
My code:
local as = game:GetService("AssetService")
local peeboxwidth = 45
local p = as:CreateEditableMesh()
function makegrid(resolution, height)
local r = table.create(resolution, table.create(resolution, 0))
for i=1,resolution do
for j=1,resolution do
r[i][j] = p:AddVertex(
Vector3.new(-(peeboxwidth/2)+((i-1)/(resolution-1))*peeboxwidth, -- Indexing starting at one makes me explode
height,
-(peeboxwidth/2)+((j-1)/(resolution-1))*peeboxwidth))
print(i, j, p:GetPosition(r[i][j]))
end
end
return r
end
local g = makegrid(2,0)
print(p:GetPosition(g[1][1]), "E", p:GetPosition(g[1][2]), "E", p:GetPosition(g[2][1]), "E", p:GetPosition(g[2][2]))
Output:
1 1 -22.5, 0, -22.5 -- Vertex 1,1 has position -22.5, 0, -22.5
1 2 -22.5, 0, 22.5
2 1 22.5, 0, -22.5
2 2 22.5, 0, 22.5
22.5, 0, -22.5 E 22.5, 0, 22.5 E 22.5, 0, -22.5 E 22.5, 0, 22.5 -- Vertex 1,1 has position 22.5, -22.5
-- Notice how vertices 1,1 and 2,1 are identical, and so are 1,2 and 2,2 (none of them being anything like what I set them to)