rEye = Droid.rEye rEyex = rEye.CFrame.x rEyey = rEye.CFrame.y rEyez = rEye.CFrame.z local weld = Instance.new("Weld", game.JointsService) weld.Part0 = Head weld.Part1 = rEye weld.C0 = CFrame.new(rEyex, rEyey, rEyez)
As you can see I have stored all the CFrame positions of rEye, and then reset the positions to that in the weld's properties, but the positioning in-game is wildly different from the positions before the weld. What am I doing wrong?
What happens when you weld two parts, is that they get CFramed inside of eachother. You need to set the C0
and C1
properties of the weld by the inverses of CFrames from the parts. You can do this with the inverse
method of CFrames.
The inverse method, well, inverses the CFrame. it makes it so that something like CFrame.new(1,-3,5)
becomes CFrame.new(-1,3,-5)
.
So since C0 is the offset of Part0
from Part1
then when you set the C0 as the inverse of Part0's CFrame then it will set the position to the origin of the workspace: CFrame.new(0,0,0).
Then, since C1 is just an offset to C0 then it will return Part0 back to it's original position. Part1 never moves throughout this process.
rEye = Droid.rEye local weld = Instance.new("Weld", game.JointsService) weld.Part0 = Head weld.Part1 = rEye weld.C0 = Head.CFrame:inverse() weld.C1 = rEye.CFrame:inverse()