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

CFrame isn't positioning correctly, help?

Asked by
drew1017 330 Moderation Voter
9 years ago
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?

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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()
0
Thanks, but could you go more indepth explaining what happens? Im not sure how inversing C1 and C0 would put the part back in its original position. drew1017 330 — 9y
0
Edited(: Goulstem 8144 — 9y
0
Very clever, thanks. drew1017 330 — 9y
0
No problem. Goulstem 8144 — 9y
Ad

Answer this question