I am making a side project which is a horror / puzzle type of game, but there’s one problem which is stopping me from developing further as I want to fix this. So, I have 3 beakers, which are aligned, but when I add another beaker, it doesn’t center properly. Here’s a video of the issue:
When you want the beakers to be aligned, does it mean it mean that the middle of the 4 beakers matches with the middle of the camera or the middle of the table?
In the video, the middle of the beakers seem to be aligned with the middle of the camera, but the beakers are not aligned with the middle of the table. I noticed that the table moved a few studs to the left (relative to the camera) between the two setups. See if the position of table changed to check if it moved.
Hope this helps!
maybe set your spacing to a different value whenever a new one is added. Because the spacing looks like it’s the same in the video the first test and the second one.
You probably set up your spacing formula wrong. Ideally, every beaker should be equally spaced while also staying on the table. You can get all the beakers to align properly by finding the amount they should be spaced apart.
local tableLength = 10
local beakerNum = 4
beakerSpacing = tableLength/(beakerNum-1)
local cfDirection = CFrame.new(1,0,0) -- the direction your beakers are lined up in, make sure it's a unitVector or your spacings will be messed up
for i=1,beakerNum do
local beaker = beakers[i]
beaker.CFrame = initialCFrame + (i-1)*beakerSpacing*cfDirection
end
Using beakerSpacing, you can apply the positions correctly.
What does your code look like? Assuming the leftmost beaker is the first one, you have your initialCFrame set wrong, it should be the leftmost point on the table that you want the beaker to rest.
If you’re centering around a primary part then your formula will be mostly the same, you’ll just want to apply it differently
for i=1,beakerNum do
local startPoint = initialCFrame - cfDirection*(tableLength/2)
-- initialCFrame is the middle of the table
local beaker = beakers[i]
beaker.CFrame = startPoint + (i-1)*beakerSpacing*cfDirection
end