As I am currently making my own custom animator I need to be able to get every part in a rig that can be animated(Attached with motor6Ds and what not)
I found this tutorial with code that well in theory loops through all the parts in the rig and if they are attached to a motor then it’d return it, but all it returns is the root and torso, why is this?
local function getAnimatables(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
end
end
end
end
end
addPoses(rootPart)
return partsAdded
end
I can see that it gets all the joints in a part and what not but like yeah no clue tbh
I believe the function only finds item connected to the root. Try doing this, not tested so idk if it will work:
local function getAnimatables(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
addPoses(connectedPart)
end
end
end
end
end
addPoses(rootPart)
return partsAdded
end
Ok so this is still giving me just the torso and root, I modified the code a little but nothing that would break it! Im so confused!
local function getAnimatables(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart.Name] = rootPart
local function addPoses(part)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart.Name] = connectedPart
end
end
end
end
end
addPoses(rootPart)
return partsAdded
end
you never add the pose of the connected part… You have to call the addpose again…
local function getAnimatables(model)
if not model.PrimaryPart then
warn("No primary part set")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Root part not found")
return
end
local partsAdded = {}
partsAdded[rootPart.Name] = rootPart
local function addPoses(part)
-- get all of the joints attached to the part
for _, joint in pairs(part:GetJoints()) do
-- we're only interested in Motor6Ds
if joint:IsA("Motor6D") then
-- find the connected part
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- make sure we haven't already added this part
if not partsAdded[connectedPart] then
partsAdded[connectedPart.Name] = connectedPart
addPoses(connectedPart)
end
end
end
end
end
addPoses(rootPart)
return partsAdded
end
Addposes recalls the function though, although yes it works but then this happens:
▶ Script 'user_Animate.rbxmx.Animate.Control', Line 98 - function addPoses (x4996)```
it gets used 5K times which lags out everything so that wont work
local AddedParts = {}
for _, i in pairs(Rig:GetChildren()) do
if i:FindFirstChildOfClass("Motor6D") then
for a, v in pairs(i:GetChildren()) do
if v:IsA("Motor6D") then
if table.find(AddedParts, v.Part1) == nil then
table.insert(AddedParts, v.Part1)
end
end
end
end
end
That would not work because it does not include the possibility of having disconnected Motor6D’s or flipped Motor6D’s. However, a modified version of this code would work significantly better than what he had, I was just too lazy to try to explain what I would write.
local function Display(rigs)
-- display rigs and there animtable objects
local Animatables = {}
local motors = {}
for _, rig:Model in pairs(rigs) do -- get animatable objects
local rigData = {
Animatables = {},
Anim = nil
}
local parts = getAnimatables(rig)
for name, part in pairs(parts) do
print(name,part)
end
-- get all parts and see if they are attached in any way.
end
end