Hello there! I’m working on a script and i have a problem. Map doesnt generate. The problem is in CheckOnCollision function,but i didnt release whats the problem
code:
local mapmodule = require(game.ServerStorage.Modules.Map)
local mapfolder = workspace.Map
function smallRound(num)
local drob = num - math.floor(num)
if drob < 0.09 then
return math.floor(num)
end
return num
end
function checkOnCollision(vector1,vector2,list)
local selfV0 = vector1
local selfV1 = vector2
local size = 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(size.X,0,0)
local bottomRightCornerSelf = selfV0 + Vector3.new(0,0,size.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.1 and range <= 1.1
local a = bottomLeftCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
totalFalse+=1
isBetween0 = false
end
local range = (v0-v1).unit:Dot(topLeftCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween1 = range > -0.1 and range < 1.1
local a = topLeftCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
totalFalse+=1
isBetween1 = false
end
local range = (v0-v1).unit:Dot(bottomRightCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween2 = range >= -0.1 and range <= 1.1
local a = bottomRightCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
totalFalse+=1
isBetween2 = false
end
local range = (v0-v1).unit:Dot(topRightCornerSelf-v1) / (v0-v1).magnitude
local range = smallRound(range)
local isBetween3 = range >= 00.1 and range <= 1.1
local a = topRightCornerSelf
if a == bottomLeftCorner or a == bottomRightCorner or a == topLeftCorner or a == topRightCorner then
totalFalse+=1
isBetween3 = false
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
end
function getLocationPos(list,x,z)
local possibleLocations = {}
local pos1
local pos2
for _, i in pairs(list) do
local v0 = i[1]
local v1 = i[2]
local size = Vector3.new(math.abs(v1.X-v0.X),0,math.abs(v1.Z-v0.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
for _, i in pairs(game.ServerStorage.Locations:GetChildren()) do
local iSize = i:GetExtentsSize()
pos1 = bottomLeftCorner+Vector3.new(0,0,iSize.Z)
pos2 = bottomLeftCorner+Vector3.new(iSize.X,0,iSize.Z*2)
local isCollides,a0,a1,a2,a3,f = checkOnCollision(pos1,pos2,list)
if not isCollides then
if pos1.X <= x and pos1.Z <= z and pos2.X <= x and pos2.Z <= z then
table.insert(possibleLocations,{i.Name,pos1})
continue
end
end
pos1 = bottomLeftCorner+Vector3.new(iSize.X,0,0)
pos2 = bottomLeftCorner+Vector3.new(iSize.X*2,0,iSize.Z)
local isCollides,a0,a1,a2,a3,f = checkOnCollision(pos1,pos2,list)
print(a0,a1,a2,a3,f)
if not isCollides then
if pos1.X <= x and pos1.Z <= z and pos2.X <= x and pos2.Z <= z then
table.insert(possibleLocations,{i.Name,pos1})
continue
end
end
end
for _, i in pairs(possibleLocations) do
local locationName,pos = mapmodule.ChooseRandomLocationOfList(possibleLocations)
if locationName then
local location = game.ServerStorage.Locations[locationName]:Clone()
location:SetPrimaryPartCFrame(CFrame.new(pos))
location.Parent = workspace.Map
return location,pos1,pos2
end
end
end
end
function Standart(xsize,zsize)
workspace.MapLoaded.Value = false
local occupied = {}
mapfolder:ClearAllChildren()
wallsFolder:ClearAllChildren()
local x = 0
local MaxXmult = 1
local xMultiplier
local zMultiplier
local plots = {}
while x < xsize*zsize do
if #occupied > 0 then
local location,pos1,pos2 = getLocationPos(occupied,xsize,zsize)
if pos1 and pos2 then
table.insert(occupied,{pos1,pos2})
end
else
local location = game.ServerStorage.Locations:GetChildren()[math.random(1,#game.ServerStorage.Locations:GetChildren())]:Clone()
local size = location:GetExtentsSize()
location.Parent = workspace.Map
location:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,0)))
table.insert(occupied,{Vector3.new(0,0,0),Vector3.new(0+size.X,0,size.Z)})
end
wait()
x+=1
end
workspace.MapLoaded.Value = true
end
I don’t have any errors in console.