I don’t know whether it works or this is the biggest waste of time I ever did since I’m kinda in a hurry, so might as well not work at all. Basically this script creates a “Wall” class which handles positions, rotations and collisions. You can create a new wall with classWall.new(CollisionSize,WallModelToClone).
local classWall do
local v3Id = Vector3.new()
local listWallCollision = {}
local listWallModels = {}
local wallIsColliding = function(self)
local partColl0 = self.CollisionPart
local pos0,size0 = partColl0.Position, partColl0.Size/2
local x00,x01 = pos0.X-size0.X,pos0.X+size0.X
local y00,y01 = pos0.Y-size0.Y,pos0.Y+size0.Y
local z00,z01 = pos0.Z-size0.Z,pos0.Z+size0.Z
for _, partColl1 in next, listWallCollision do
local pos1,size1 = partColl1.Position, partColl1.Size/2
local x10,x11 = pos1.X-size1.X,pos1.X+size1.X
local y10,y11 = pos1.Y-size1.Y,pos1.Y+size1.Y
local z10,z11 = pos1.Z-size1.Z,pos1.Z+size1.Z
if (x10<x00 and x00>x11) or (x10>x00 and x00<x11) then
if (x10<x00 and x00>x11) or (x10>x00 and x00<x11) then
if (x10<x00 and x00>x11) or (x10>x00 and x00<x11) then
return true
end
end
end
end
end
local wallCheckValidity = function(self)
if self:IsColliding() then
self:Destroy()
return false
end
end
local wallTilt = function(self,direction)
direction = direction or 1
local partColl = self.CollisionPart
local cf = partColl.CFrame
partColl.Size = Vector3.new(partColl.Size.Z,partColl.Size.Y,partColl.Size.X)
partColl.CFrame = cf
if self:CheckValidity() then
local modelVisual = self.VisualModel
modelVisual.CFrame = modelVisual.CFrame*CFrame.Angles(0,math.rad(90)*direction,0)
end
end
local wallSetPosition = function(self,position)
local partColl = self.CollisionPart
partColl.CFrame = CFrame.new(position)
if self:CheckValidity() then
local modelVisual = self.VisualModel
modelVisual.CFrame = modelVisual.CFrame-modelVisual.CFrame.Position+position
end
end
local wallDestroy = function(self)
local partColl = self.CollisionPart
local modelVisual = self.VisualModel
listWallCollision[modelVisual] = nil
table.remove(listWallModels,table.find(listWallModels,modelVisual))
partColl:Destroy()
modelVisual:Destroy()
end
classWall = {
new = function(size,model)
local modelVisual = model:Clone()
modelVisual.Parent = workspace
local partColl = Instance.new("Part")
partColl.Anchored = true
partColl.Transparency = 1
partColl.Parent = workspace
listWallCollision[modelVisual] = partColl
listWallModels[#listWallModels+1] = modelVisual
return {
Position = v3Id,
Size = size,
VisualModel = modelVisual,
CollisionPart = partColl,
IsColliding = wallIsColliding,
CheckValidity = wallCheckValidity,
SetPosition = wallSetPosition,
Tilt = wallTilt,
Destroy = wallDestroy
}
end
}
end
do
local wall1 = classWall.new(Vector3.new(8,4,1),somemodel1)
local wall2 = classWall.new(Vector3.new(5,5,1),somemodel2)
wall1:SetPosition(Vector3.new(0,0,0))
wall2:SetPosition(Vector3.new(5,0,0))
end