I making some sort of card game that makes you hold the cards when you’re playing the game and I tried offsetting the pivot so it’ll seem like you’re actually holding the cards.
function RePositionCards() -- Self Explanatory
for i, v in pairs(Cards:GetChildren()) do
local CardPosition = CFrame.new(Vector3.new(v:GetPivot().Position.X, v:GetPivot().Position.Y, v:GetPivot().Position.Z))
local Angles = CFrame.Angles(math.rad(v:GetPivot().Rotation.X), math.rad(v:GetPivot().Rotation.Y), math.rad(i/(#Cards:GetChildren()+2)*180))
v:PivotTo(CardPosition * Angles)
end
end
local CardPosition = CFrame.new(Vector3.new(v:GetPivot().Position.X, v:GetPivot().Position.Y, v:GetPivot().Position.Z))
This is a lot of redundancy, you can just do:
local pivot = v:GetPivot()
local CardPosition = CFrame.new(pivot.Position)
You’ll also see that I localized the pivot call. Try to avoid calling functions multiple times in the future, because a simple variable lookup will always be faster than a function call!
Next is the actual problem, which is the rotation. Assuming what you have set up, you can just add a constant to your Z rotation to give all of your cards a relative rotation around the pivot:
local Angles = CFrame.Angles(math.rad(pivot.Rotation.X), math.rad(pivot.Rotation.Y), math.rad(90) + math.rad(i/(#Cards:GetChildren()+2)*180))
This is really great advice, but I still get the same result somehow.
Something tells me that I used wrong type of constraint and used the weld constraint instead of something else but I don’t know.
Cards.ChildAdded:Connect(function(child) -- "Cards" is a folder for cards
child:PivotTo(Hand.WorldCFrame) -- The "Hand" is an attachment
child.WeldConstraint.Part1 = RHand
RePositionCards()
end)
A normal Weld instance is more practical for your case I’d like to say. Not to say that weld constraints are bad or anything, it’s just a weirdly different setup that has some pros and cons compared to Welds and Motor6Ds.