-
What do you want to achieve?
Hi, im trying to make a cards game and i want to position the cards across a part like this: (kind of like the UIGridLayout when set to “Center.”)
But I also would like the cards to be positioned equal distances from each-other without from the center, like this:
-
What is the issue?
So far ive been trying to divide the X size of the main part, by the number of cards. Then positioning the card by doing (card number * result of previous equation.)
Which results in the cards still not being in the center.
local cards = workspace.Cards:GetChildren()
local l1 = workspace.Layers.Layer1 --BasePart for cards to go against
local cardsXOrigin = l1.Position-Vector3.new(0,0,(l1.Size.X/2))
--Create part to see where the cardsXOrigin is
local p = Instance.new("Part",workspace); p.Position = cardsXOrigin; p.Anchored = true; p.Size = Vector3.new(.1,.1,.1); p.Name = "A"; p.Color = Color3.fromRGB(255, 128, 0)
local offs = l1.Size.X/#cards
---[[Loop through all the cards and position them acoordingly
for i,card in ipairs(cards) do
card.CFrame = l1.CFrame*CFrame.new(Vector3.new(0,0,-l1.Size.Z/2 - card.Size.Z/2)) --Positioning them on top of the layer1 part
card.Position = Vector3.new(card.Position.X,card.Position.Y,(cardsXOrigin.Z+i*offs)) --Moving it across the Z axis
end
---]]
This is the result im getting:
I’ve tried offsetting each card, by half the X size of the card.
But it still isn’t centered:
The code i used to offset it:
card.Position = Vector3.new(card.Position.X,card.Position.Y,(cardsXOrigin.Z+i*offs))+Vector3.new(0,0,-card.Size.X/2)
Any help would be apreciated.
Thanks!