Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Formula to simulate welds via CFrame?

Asked by
Sparker22 190
4 years ago
Edited 4 years ago

I'm designing out a character customization UI. I'm trying to properly position accessories to the character. I can't use the usual accessory functions on the humanoid because this is on the client, and physics isn't simulated in viewport frames to use a usual weld function. Parenting to workspace and back feels like a very unclean and unpredictable method so i'd like to just simulate what the weld would do. Here is the equivalent I am trying to reproduce:

function weldAttachments(attach1, attach2)
    local weld = Instance.new("Weld")
    weld.Part0 = attach1.Parent
    weld.Part1 = attach2.Parent
    weld.C0 = attach1.CFrame
    weld.C1 = attach2.CFrame
    weld.Parent = attach1.Parent
    return weld
end

I'm not really sure how i'd calculate where it would go but I have tried this which isn't quite right:

function cframe(CharAttach, AccAttach)
    local part0 = CharAttach.Parent
    local part1 = AccAttach.Parent
    local c0 = CharAttach.CFrame
    local c1 = AccAttach.CFrame
    part1.CFrame = part0.CFrame:toWorldSpace(c0):toWorldSpace(c1)
end

Any advice and help would be appreciated, thanks!

Answer this question