I have a model that I am attempting to clone beside each other. I’ve gotten so far as to get the models close to what I need but I am unsure how to complete the calculations so that each model is in the correct position. I intend to do this on all sides eventually but I want to get the first side complete. As you can see the first model is correctly located but when I try to loop more in they overlap.
--//BOX PLACEMENT SCRIPT
--This script should place the boxes along the side of the
--starter area.
--//SERVICES
local RS = game:GetService("ReplicatedStorage")
--//VARIABLES
local boxFolder = RS:WaitForChild("BoxFolder")
local box = boxFolder:WaitForChild("Box")
local boxes = workspace.Boxes
local floorArea = workspace.FloorArea
--//FUNCTIONS
local function getStartCoord()
--get the size of the placement area
local floorSizeX = floorArea.Size.X
local floorSizeY = floorArea.Size.Y
local floorSizeZ = floorArea.Size.Z
local setY = floorSizeY/2 + floorSizeY/2 --top of the floor area
--get the corner position at the top of the floorarea
local StartCornerA = Vector3.new(-floorSizeX/2, setY, -floorSizeZ/2)
--local newPart = Instance.new("Part")
--newPart.Size = Vector3.new(4,4,4)
--newPart.Color = Color3.new(1,0,0)
--newPart.Anchored = true
--newPart.Position = StartCornerA
--newPart.Parent = workspace
return StartCornerA
end
local function getPlacementPosition()
--get the position of each box position
--loop through at least 10 boxes for one side
--get the other sides after one side is correct
local startSpot = getStartCoord()
local floorSizeX = floorArea.Size.X
local boxSizeX = box.BoxBase.Size.X
local numberOfSpawns = math.floor(floorSizeX / boxSizeX)
--print("The number of boxes that can spawn is: ", numberOfBoxes)
--calculate first box position
--local coordY = boxClone.PrimaryPart.Size.Y/2
--local coordX = boxClone.BoxBase.Size.X / 2
--local coordZ = Vector3.new(boxClone.BoxBase.CFrame.Z - boxClone.PrimaryPart.CFrame.Z).Magnitude
--boxClone:PivotTo(CFrame.new(startSpot) + Vector3.new(coordX,coordY,coordZ - coordZ + 6))
--boxClone.Parent = boxes --boxes folder in workspace
for i = 1, numberOfSpawns do
local boxClone = box:Clone()
local coordY = boxClone.PrimaryPart.Size.Y/2
local coordX = boxClone.BoxBase.Size.X / 2
local coordZ = Vector3.new(boxClone.BoxBase.CFrame.Z - boxClone.PrimaryPart.CFrame.Z).Magnitude
boxClone:PivotTo(CFrame.new(startSpot) + Vector3.new(coordX * i,coordY,coordZ - coordZ + 6))
boxClone.Parent = boxes --boxes folder in workspace
--how to fix boxClone overlapping?
end
end
local function modifyBoxes()
--modify box properties
--set box mechanics
--apply new texts and labels
end
getPlacementPosition()
I apologize for the formatting of the code (WIP)