I’m trying to allow the client to rotate their accessories. AFAIK, this has to be done by rotating a CFrame of the weld because if you rotate the Handle it rotates the whole character. The problem I am having is that if you change the orientation of the weld’s CFrames, this creates an orbital movement around the Attachment. This isn’t an issue for some accessories based on the positioning of their attachment.
I’ve been scouring around in resources to try to figure it out but nothing has helped.
local function worldCFrameRotationToC0ObjectSpace(motor6DJoint,worldCFrame)
local part0 = motor6DJoint.Part0
local c1Store = motor6DJoint.C1
local c0Store = motor6DJoint.C0
local relativeToPart0 = part0.CFrame:inverse() * worldCFrame * c1Store
local goalC0CFrame = relativeToPart0
return goalC0CFrame
end
local ContextActionService = game:GetService("ContextActionService")
local rotation = 0
ContextActionService:BindAction("t", function(n, inputState)
rotation += 5
local Accessory = game.Players.LocalPlayer.Character:FindFirstChild("Woman Face")
local Weld = Accessory.Handle.AccessoryWeld
local C0 = Weld.C0
local part1 = Weld.Part1
local goalWorldSpaceCFrame = CFrame.Angles(0, 0, math.rad(rotation)*part1.CFrame
Weld.C0 = worldCFrameRotationToC0ObjectSpace(Weld, goalWorldSpaceCFrame)
end, false, Enum.KeyCode.T)
Thanks for making the effort to try it out. It was just an idea I had in my head.
Turns out it’s weirder since for accessories since the part0 and part1 is swapped.
Normally the part0 is the one closer to the root part.
So I used the formula for C1 instead and it worked…seems like swapping the part0 and part1 reverses the formulas for C0 and C1.
local accessoryWeld = script.Parent.AccessoryWeld
local Weld = accessoryWeld
local function worldCFrameRotationToC1(motor6DJoint, worldCFrame)
local part0 = motor6DJoint.Part0
local c0Store = motor6DJoint.C0
return worldCFrame:Inverse() * part0.CFrame * c0Store
end
while true do
local dt = task.wait()
local C0 = Weld.C0
local part0 = Weld.Part0
local rotation = 100*dt
local goalWorldSpaceCFrame = (CFrame.Angles(0, 0, math.rad(rotation))*part0.CFrame).Rotation + part0.Position
Weld.C0 = worldCFrameRotationToC1(Weld, goalWorldSpaceCFrame)
end