I’m trying to make a script based on converting poses in workspace to keyframes in an animation.
Right now, I’m having trouble getting the formula for converting the CFrame into the correct place in the animation, because if I just set the pose .CFrame to the CFrame I want, it doesn’t display the poses in workspace properly. If I could get help finding the correct formula for the script that would be appreciated,
-- This is what I have to far:
-- The array is sorted like {Head.CFrame, LeftArm.CFrame, RightArm.CFrame, Torso.CFrame, LeftLeg.CFrame, RightLeg.CFrame}
for keyframeindex, arrayofcframes in ipairs(keyframes) do
local keyframeindexmodel = folder:FindFirstChild(keyframeindex)
local keyframe = Instance.new("Keyframe")
keyframe.Time = animationtime
keyframe.Name = tostring(keyframeindex)
local rootPose = Instance.new("Pose")
rootPose.Name = "HumanoidRootPart"
rootPose.Weight = 0
keyframeSequence:AddKeyframe(keyframe)
keyframe:AddPose(rootPose)
local torsopart = keyframeindexmodel:FindFirstChild("Torso")
local torsopose = Instance.new("Pose")
torsopose.Name = torsopart.Name
torsopose.Weight = 1
torsopose.CFrame = arrayofcframes[4] --need help with this line
rootPose:AddSubPose(torsopose)
for arrayindex, cframe in ipairs(arrayofcframes) do
if cframe ~= nil then
local bodypart = keyframeindexmodel:FindFirstChild(bodyparts[arrayindex][2])
if bodypart.Name ~= "Torso" then
local pose = Instance.new("Pose")
pose.Name = bodypart.Name
pose.Weight = 1
local joint = getJointBetween(keyframeindexmodel:FindFirstChild("Torso"), bodypart)
pose.CFrame *= joint.Transform:Inverse() * joint.C1:Inverse() --and this line
rootPose:AddSubPose(pose)
end
end
end
animationtime += .016
end
return keyframeSequence
end
Sorry for the late response, but could you tell me what keyframeindex is? Also, would recommend just having
for arrayindex, cframe in ipairs(arrayofcframes) do
if cframe ~= nil then
keyframeindexfolder = folder:FindFirstChild(keyframeindex)
arrayind = arrayindex
local posechar = keyframeindexfolder:FindFirstChild(bodyparts[arrayind][2])
local pose = Instance.new("Pose")
pose.Name = bodyparts[arrayindex][2]
pose.Weight = 1
pose.CFrame = posechar.CFrame
rootPose:AddSubPose(pose)
end
end
changed it to posechar instead of going back to the thing directly.
Alright. Could you show me what bodyparts is? Are there any errors? Also, try printing posechar
for arrayindex, cframe in ipairs(arrayofcframes) do
if cframe ~= nil then
keyframeindexfolder = folder:FindFirstChild(keyframeindex)
arrayind = arrayindex
local posechar = keyframeindexfolder:FindFirstChild(bodyparts[arrayind][2])
print(posechar)
local pose = Instance.new("Pose")
pose.Name = bodyparts[arrayindex][2]
pose.Weight = 1
pose.CFrame = posechar.CFrame
rootPose:AddSubPose(pose)
end
end
The bodyparts is a seperate variable outside of the loop that defines all of the bodyparts in the r6 model to get. I really just need a formula to position the CFrame in the animation correctly on this line
Well, I’ll ask the obvious question. Why don’t you just use cframe? It seems like arrayofcframes would contain all of the cframes needed, and you are iterating over it.
Arrayofcframes just stores all of the cframes needed for the keyframe, I am using cframes for it but the animation doesn’t display properly when I just set the CFrames for each of the body parts in the keyframe, which I am thinking of is because of the Motor6D’s.
I’m not sure then. If the animation’s cframes are all correct, there shouldn’t be an issue. I don’t work with animations much, but it could be the Motor6Ds. If you are using Motor6D’s with the arm, use it with the torso instead since it can mess up arm movements.