Imitating Welds Using CFrame

I need to imitate how welds work using CFrame and math (preferably without the use of weld instances at all) because physics doesn’t work in ViewportFrames. I’m making a backpack GUI that renders tools inside the slots, so the weld imitation must use tool grips.

A solution to a similar problem, but with attachments and accessories.

How about you put everything in a model and move the PrimaryPart Cframe? It will act as if everything that’s in the model is welded.

Important bit from the page on Welds (Weld):

While the weld is Active , it maintains the part positions such that:
Part1.CFrame * C1 == Part0.CFrame * C0

That means that if you have a weld, you can solve for the positions of each part:
Part1.CFrame = Part0.CFrame * C0 * C1:Inverse()
Part0.CFrame = Part1.CFrame * C1 * C0:Inverse()


Also, and I think this is a much better solution than calculating the CFrames of each part of the tool manually, you can keep using welds in a ViewportFrame as long as the parts are parented under a WorldModel. The engine will physically simulate the CFrames of each part correctly.

(I would suggest trying out this solution first.)


I took a bit of a break, so that’s why this reply is so late.
I tried out data models and the results are weird.

Desired result: (using workspace) (btw those white parts are what the handles are welded to)

WorldModel Result:

For some reason, the CFrame of the handle, when using WorldModel is different from the CFrame of the handle when using Workspace. And the handle holder parts are nowhere to be seen.

Workspace — Pos: -7.918, 2.966, 0.262 | Orientation: 0, 0, -40
WorldModel — Pos: -0.431, 0.669, -1.406 | Orientation: 0.65, 92.93, 144.9

I’m very confused.

Hmm, can you try bumping up the RootPriority of the tool’s handle to 1? Make sure it isn’t massless either. I suspect that the physics engine isn’t choosing the handle as the RootPart after welding, which is giving you weird results.

1 Like

Doesn’t work; same result. Sorry for the late reply, the Devforum was down.

I don’t think I can help with debugging this any further without getting my hands on it myself, sorry.

I would at least double-check to make sure that:

  1. The handle and the rest of the parts are actually welded.
  2. If you’re moving the handle inside the ViewportFrame and it’s welded using WeldConstraints, check that you are moving it by changing its CFrame property instread of it’s Position property. Updating the CFrame property moves the rest of the parts connected by the WeldConstraint, whereas updating the Position property doesn’t.
1 Like