Rotate a part with Weld.C0 but without a pivot point?

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?

Found a method for @Headstackk, tested with motor of following:

motor.C1 = CFrame.Angles(1,2,1)*CFrame.new(0,5,2)
motor.C0 = CFrame.Angles(5,2,1)*CFrame.new(0,0,5)

wacky rig setup result:

Without C1 :Inversing

With C1 Inversing:

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

How did I get this result?

With the weld CFrame formula


--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.

NVM

Try:

C0 = Motor.part0.Cframe:inverse *part1.CFrame*CFrame.angles(stuff)
10 Likes

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)

Root part

Every Assembly has a root part, see BasePart:GetRootPart . When a Weld’s C0 / C1 is modified the root part will stay where it was.

The rules for choosing a root part is here:

part1.Weld.C0 = part1.CFrame:ToObjectSpace(part2.CFrame * CFrame.Angles(math.rad(-1),0,0))

1 Like