Hello there!
I’m making a script that generates a map that contains plots. When I put only 50x50 sized plots,all works fine. But when I put 100x100 location,map becomes broken.
There is a function I use to detect a collision:
function checkOnCollision(vector1,vector2,list)
local selfV0 = vector1
local selfV1 = vector2
local sizeS = Vector3.new(math.abs(selfV0.X-selfV1.X),math.abs(selfV0.Y-selfV1.Y),math.abs(selfV0.Z-selfV1.Z))
local bottomLeftCornerSelf = selfV0
local topLeftCornerSelf = selfV0+Vector3.new(sizeS.X,0,0)
local bottomRightCornerSelf = selfV0 + Vector3.new(0,0,sizeS.Z)
local topRightCornerSelf = selfV1
for _, i in pairs(list) do
local v0 = i[1]
local v1 = i[2]
local size = Vector3.new(math.abs(v0.X-v1.X),math.abs(v0.Y-v1.Y),math.abs(v0.Z-v1.Z))
local bottomLeftCorner = v0
local topLeftCorner = v0+Vector3.new(size.X,0,0)
local bottomRightCorner = v0 + Vector3.new(0,0,size.Z)
local topRightCorner = v1
local xmin = math.min(selfV0.X,selfV1.X)
local xmax = math.max(selfV0.X,selfV1.X)
local zmin = math.min(selfV0.Z,selfV1.Z)
local zmax = math.max(selfV0.Z,selfV1.Z)
local region = Region3.new(v0+Vector3.new(-0.1,10,-0.2),v1+Vector3.new(0.1,10,0.1))
local totalFalse = 0
local range = (v0-v1).unit:Dot(bottomLeftCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween0 = range > 0 and range < 1
local a0 = true
local a1 = true
local a2 = true
local a3 = true
if bottomLeftCornerSelf.X == v0.X or bottomLeftCornerSelf.X == v1.X
and bottomLeftCornerSelf.Z == v0.Z or bottomLeftCornerSelf.Z == v1.Z then
if a0 then
totalFalse+=1
a0 = false
end
if isBetween0 then
isBetween0 = false
a0 = false
end
end
local a = bottomLeftCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
if a0 then
totalFalse+=1
a0 = false
end
if isBetween0 then
isBetween0 = false
end
end
local range = (v0-v1).unit:Dot(topLeftCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween1 = range > 0 and range < 1
if topLeftCornerSelf.X == v0.X or topLeftCornerSelf.X == v1.X
and topLeftCornerSelf.Z == v0.Z or topLeftCornerSelf.Z == v1.Z then
if a1 then
totalFalse+=1
a1 = false
end
if isBetween1 then
isBetween1 = false
end
end
local a = topLeftCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
if a1 then
totalFalse+=1
a1 = false
end
if isBetween1 then
isBetween1 = false
end
end
local range = (v0-v1).unit:Dot(bottomRightCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween2 = range > 0 and range < 1
if bottomRightCornerSelf.X == v0.X or bottomRightCornerSelf.Z == v0.X
and bottomRightCornerSelf.X == v1.Z or bottomRightCornerSelf.Z == v1.Z then
if a2 then
totalFalse+=1
a2 = false
end
if isBetween2 then
isBetween2 = false
end
end
local a = bottomRightCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
if a2 then
totalFalse+=1
a2 = false
end
if isBetween2 then
isBetween2 = false
end
end
local range = (v0-v1).unit:Dot(topRightCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween3 = range > 0 and range < 1
if topRightCornerSelf.X == v0.X or topRightCornerSelf.Z == v0.X
and topRightCornerSelf.X == v1.Z or topRightCornerSelf.Z == v1.Z then
if a3 then
totalFalse+=1
a3 = false
end
if isBetween3 then
isBetween3 = false
end
end
local a = topRightCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
if a3 then
totalFalse+=1
a3 = false
end
if isBetween3 then
isBetween3 = false
end
end
isBetween0 = false
--isBetween1 = false
--isBetween2 = false
--isBetween3 = false
--print(isBetween0,isBetween1,isBetween2,isBetween3,totalFalse)
if isBetween0 or isBetween1 or isBetween2 or isBetween3 or totalFalse >= 4 then
return true,isBetween0,isBetween1,isBetween2,isBetween3,totalFalse
else
--return false
end
end
return false
vector1 and vector2 are 2 opposite corners of plot ex. 0,0,0 and 50,0,50.
list contains an array of two opposite corners ex.:
{ {Vector3.new(0,0,0),Vector3.new(50,0,50)} , {Vector3.new(0,0,50),Vector3.new(50,0,100)} }
only 50x50:
with 100x100 one plot size: