Hello! I have been trying to make these panels that flip every time you jump for some experiments and was having trouble designing a tween to allow for the platform to rotate 180 degrees regardless of the model’s rotation along the hinge part I have. If I don’t have the model oriented in this very specific axis, then the platform part either spins in place, upside down, or in some other strange direction for the rotation. I suspect it has something with performing the rotation relative to object space rather than world space, but I am not the best at using CFrames, so any help would be appreciated.
I have tried using CFrame.fromOrientation() and also tried multiplying by the orientation of the hinge part (the metallic part in the pictures), but neither worked.
Desired Rotation, but it breaks when I rotate the model in any other direction.
Code Snippet, Non-relevant parts removed:
--Preparing the CFrame to be tweened using a CFrameValue that is binded to a signal.
--Probably a better way to do this?
for _, item in ipairs(allParts) do
if item:IsA("Model") and item.Name == "FlipSwap"then
table.insert(panels, item)
item.Panel.CFrameState:GetPropertyChangedSignal("Value"):Connect(function()
item.Panel.PrimaryPart:PivotTo(item.Panel.CFrameState.Value)
end)
end
end
--Animation Step
local tweens = {}
for _, model in ipairs(panels) do
--Ties the CFrame value in the model to the tween to be updated by a tween later.
local modelPanel = model.Panel
modelPanel.CFrameState.Value = modelPanel.PrimaryPart:GetPivot()
table.insert(tweens, TweenService:Create(modelPanel.CFrameState,tweenInfo,{Value = CFrame.Angles(0, 0, -math.pi)*modelPanel.PrimaryPart:GetPivot().Rotation + modelPanel.PrimaryPart:GetPivot().Position}))
end