Converting a r6 rig model's static pose in workspace into a keyframe

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
1 Like

I’m going to ask a few questions before I try to answer this. For one,

did you mean to search for keyframeindex? Also, why are you redefining a variable?

Why make another variable here? It isn’t really needed.

1 Like

There’s a variable outside the loop I define from inside of the loop.

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.

keyframeindex is a number that finds the model in the folder.

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

pose.CFrame = posechar.CFrame

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.

Although I can make the CFrame line this,

pose.CFrame = cframe

It still doesn’t work as intended.

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.