There are 2 parts. A weld is connected both parts with the Red Part being the Part0 and Grey Part being Part1.
When I rotate the part with the code: workspace.RedPart.Weld.C0 = workspace.RedPart.Weld.C0 * CFrame.Angles(math.rad(-1),0,0), the red part acts like a pivot due to a 6 studs C0 offset between both parts. Is it possible to rotate the grey part locally with math?
This is the desired outcome that I want, but how to do it with code and setting the C0 of the weld?
while true do
local dt = task.wait()
local additionalRotation = CFrame.Angles(math.pi/2*dt,0,0)
additionalRotation = motor.C1:Inverse()*CFrame.Angles(math.pi/2*dt,0,0)*motor.C1--magic trick
motor.C0 *= additionalRotation
end
--part1.CFrame * C1 == Part0.CFrame * C0 --how welds work
--Let C0 be equal to C0*someCF
--C0 = normal C0 before anything was changed
--someCF is the additionalRotation we want to apply to the Part1 CFrame via CFrame multiplication
--because the weld formula is maintained someCF is added to both sides
--part1.CFrame * C1*someCF == Part0.CFrame * C0*someCF
--To apply rotation to Part1CFrame and not it's C1 we inverse it to cancel out the C1
--Apply this both sides as well
--part1.CFrame * C1*C1:Inverse()*someCF == Part0.CFrame * C0*C1:Inverse()*someCF
--part1.CFrame *someCF == Part0.CFrame * C0*C1:Inverse()*someCF
--we want to maintain original C1 offset so we add that in
--part1.CFrame *someCF*C1 == Part0.CFrame * C0*C1:Inverse()*someCF*C1
--Overall C0 change we need to set to to apply someCF to Part1 CFrame
--C0 = C0*C1:Inverse()*someCF*C1
Edit:
NVM this Part0 Inverse method hidden below seems to only work for CFrame.lookat cases with a static goal CFrame like this one with a head lerping to mouse position.
Thanks for your detailed explanation, but I have found out that this happening because Part0 is larger than Part1. Apparently the root part is determined by the part size. (like why???)
Sorry for the late reply but yeah that’s how it do work the weld part closest to the root part doesn’t move while the part that is furthest from the root part moves. (Part with largest size included)