How can I edit a Motor6D's C0/C1 value so it faces a Model(specifically the player)

Title might be confusing so i’ll attempt to go further in-depth. I have a model(named Stand) Motor6D’d to the Player’s HumanoidRootPart.

Motor6D properties: https://gyazo.com/2b05905622c0b790abec0eb19bbf8397
StandHumanoidRootPart - HumanoidRootPart of the Stand(Model Motor6D’d to the player)

Here’s the code I used to change C0 value.

hrp.Stand2Human.C0 = CFrame.new(standhrp.Position, torso.Position)
--hrp is the Player's HumanoidRootPart
--Stand2Human is the Motor6D
--standhrp is the Stand's HumanoidRootPart
--torso is the Torso of the model the Stand is trying to rotate towards

The code above didn’t work the way I intended to. I just want to know if my goal is possible. All answers are appreciated.

1 Like

The C0 is the CFrame offset relative to the part 0 of the motor6d/joint instance that it is attached to relative to the part 0 in a similar fashion to a weld. It’s actually known as a joint instance which yeah both welds and Motor6ds inherit.

part1.CFrame * C1 == Part0.CFrame * C0

And so we can solve for the weld C0 in a similar manner.

--Solving for Weld.C0:
weld.Part0.CFrame * weld.C0 = weld.Part1.CFrame * weld.C1 
weld.Part0.CFrame:inverse() * weld.Part0.CFrame * weld.C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame * weld.C1 
CFrame.new() * weld.C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame * weld.C1 
weld.C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame * weld.C1 

This CFrame you have obtained is relative to the world and not part 0 of the motor6D.
It’s actually the part1.CFrame that we want to set the joint C0 towards.

Consequently, to make it relative to the C0 we reset the part0 CFrame like so below.

local resetPart0 = hrp.Stand2Human.Part0.CFrame:Inverse()
hrp.Stand2Human.C0 = resetPart0

This should make the part1 of the Motor6d joint go back towards the origin point of the world with an orientation of (0,0,0).

From there we can add the CFrame relative to the world in order to make it go where we want like below by “adding” a CFrame

when you multiply think of it as adding a rotation and position relative to that current CFrame

local resetPart0 = hrp.Stand2Human.Part0.CFrame:Inverse()
local desiredPart1CFrame = CFrame.new(standhrp.Position, torso.Position)

hrp.Stand2Human.C0 = resetPart0 * desiredPart1CFrame

This calculation assumes the C1 joint instance is equal to an identity CFrame.new() to make calculations simpler making the offset to this desiredPart1Cframe zero.

I tried it in my IK project and it should work for setting the desired part 1 CFrame relative to the C0 joint of a motor6d.

Hopefully, I’m correct about this I haven’t tested the exact CFrame math I used for the weld math explanation.

3 Likes

I’m busy right now so I’ll implement this when I am free. I will keep you updated though, dont worry :smile:.

It work’s perfectly. But how would I make it so that the model is slightly elevated above the player(without welding it to the head)?