Make two or multiple objects stick together in a Viewport Frame

Hello DevForum,
I recently started working on an update for my game, basically, you will open a Crate and get a random item, simple and easy, however to make everything look so much better I decided to add an animation showing the Crate opening and the item coming out of it using some ViewportFrames.

Everything runs cool and smoothly until an Item that is made out of 2 or more objects (parts, meshes, etc.) gets picked. Only one of the parts will appear in the animation making everything look broken & ugly.

I’ve tried using WeldConstraint but as we all know, they don’t work inside of ViewportFrames.

Now I can, of course, start coding each part of the Item but that would just be so messy & annoying.

Can someone help me find a better solution of doing this?

I recommend turning your part into models. That way you could use SetPrimaryPartCFrame to move a group of parts whilst moving the “main” part.

You could also manually set each parts CFrame. You would do so like this:

local Primary = "ReferenceToPart"
local Detail = "ReferenceToPartAtta hedToMain" --1
local Offset = Primary.CFrame:ToObjectSpace(Detail.CFrame) --2
Primary.CFrame = TargetCFrame
Detail.CFrame = TargetCFrame:ToWorldSpace(Offset)--3

Steps 1,2,3 has to be done manually for each part. You could also store the offset for each part in an array to make it faster. Instead of calculating it each frame.

Thirdly, You could just Parent the detail parts to the main part. It might work and it is easy to do. However, it isn’t a “clean” solution.

1 Like

I’ll try this and let you know later if it works, thanks.

1 Like

Thanks, it works just as expected, however I decided to use :PivotTo instead of :SetPrimaryPartCFrame, because it’s more of an updated version as the Documentation Website states.