local distances={
function(p1pos,p2pos) return -p1pos.Z+p2pos.Z end,
function(p1pos,p2pos) return -p1pos.X+p2pos.X+p1pos.Z-p2pos.Z end,
function(p1pos,p2pos) return -p1pos.X+p2pos.X end
}
local equations={
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X,1,p1pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X-d1,1,p1pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X+d1,1,p1pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X+d1,1,p2pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X-d2/2,1,p2pos.Z+d2/2) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X,1,p2pos.Z+d2) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X,1,p1pos.Z-d2) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X,1,p2pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X,1,p2pos.Z+d3) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X+d2/2,1,p1pos.Z-d2/2) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p1pos.X-d1,1,p2pos.Z) end,
function(p1pos,p2pos,d1,d2,d3) return Vector3.new(p2pos.X,1,p1pos.Z-d3) end,
}
These functions are used once every heartbeat. The equations array is used to get the positions of 12 parts using two root parts with a known position. Notably each part owns its own function. part1 only uses equation function 1 and so forth.
here is the code that calls the functions:
RS.Heartbeat:Connect(function()
--...
local p1pos=p1.Position
local p2pos=p2.Position
local d1=distances[1](p1pos,p2pos)
local d2=distances[2](p1pos,p2pos)
local d3=distances[3](p1pos,p2pos)
for i, part in ipairs(folder) do
part.Position=equations[i](p1pos,p2pos,d1,d2,d3)
--...
end)
I saw once that it was bad to store code as a massive block and as such am wondering if there is a better way to store all my functions.