I have an automatic rigging system in place for some of my models, which seems to work perfectly when playing animations, however changing the position of the RootPart for some reason causes the RootJoint Motor to go haywire. This doesn’t affect the rest of the Rig, only the Motor6d C0 property of the RootJoint. The expected behavior (as far as I know) is for the C0 of the Motor6d to remain at “0,0,0”, but it changes unpredictably as I try to change the Part0 Position of the motor (The RootPart’s position). The below video display the issue:
(Note I interpolate the RootPart Position, that’s why the RootPart goes back to it’s original position)
The code for the rig script:
function GFX:RigPet(Pet)
local PetParts = Pet:GetChildren()
if not Pet:FindFirstChild("AnimationController") then
Instance.new("AnimationController", Pet)
end
local function CreateJoint(p0, p1, parent, name)
local Weld = Instance.new("Motor6D") -- I prefer using Motor6D
Weld.Part0 = p0
Weld.Part1 = p1
Weld.Name = name
if name == "RootJoint" then
--Desperate attempt to get the intended behavior...
Weld.C0 = CFrame.new(0,0,0)
Weld.C1= CFrame.new(0,0,0)
else
Weld.C0 = p0.CFrame:inverse() * p1.CFrame -- This is object space. Equivalent to Part1.CFrame = Part0.CFrame * Weld.C0 if world space
end
Weld.Parent = parent
end
for i,instance in pairs(PetParts) do
if instance.Name == "RootPart" then
CreateJoint(instance, Pet:FindFirstChild("Body").PrimaryPart, instance, "RootJoint")
end
if instance.Name == "Body" then
if instance:IsA("Model") then
for i,v in pairs(instance:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Body" then
CreateJoint(instance.PrimaryPart, v, v, v.Name.."Joint")
end
end
end
end
if instance.Name == "BackLLeg" or instance.Name == "BackRLeg" or instance.Name == "FrontLLeg" or instance.Name == "FrontRLeg" then
if instance:IsA("Model") then
CreateJoint(Pet.Body.PrimaryPart or Pet.Body, instance.PrimaryPart, instance.PrimaryPart, instance.Name.."Joint")
for i,v in pairs(instance:GetChildren()) do
if v:IsA("BasePart") then
CreateJoint(instance.PrimaryPart, v, v, v.Name.."BodyJoint")
end
end
else
CreateJoint(Pet.Body.PrimaryPart or Pet.Body, instance, instance, instance.Name.."Joint")
end
end
end
end