CFrame to Animation is translated incorrectly (sideways, etc.)

This is by far the most frustriating part I have to deal with, I’m unable to properly translate Local CFrame into Transform as animation is displayed sideways (this is not how I want animation to look like)

To clarify: I’m translating CFrame from player’s limb instead of copying Transform from Motor6D, since Transform only updates from animation data.

image

  • To the left is player, on the right is what my code translates CFrame to Transform, then saved to Animation Editor

I tried to come up with solution, variants of failed solutions:
image
Same sideways, trying to rotate will rotate the limb…
And a few failed attempts is limbs flying everywhere…

  • And what’s I’m gonna use this for?

To render gameplay animation & motion capture using VR Equipment.
And make a community resource for those who wants to save things into animation using CFrames

And I’m not only one who’s been trying to create cframe to animation keyframe
Converting Roblox Gameplay into an Animation (unsolved) - Help and Feedback / Scripting Support - Developer Forum | Roblox

So, I need help, this problem has me trying to solve it overnight up to 3 am occassionally.

This part where CFrame translates to Transform:

local motor6dcframe = v.Part0.CFrame
local offset
offset = (v.Part1.CFrame):ToObjectSpace(motor6dcframe)*(v.C0*v.C1:Inverse())
								
joint.Transform = offset--CFrame.new(offset.Position)--*offset.Rotation:Inverse()

Full code:

local wait = task.wait
local function generateKeyframe(model,preview)
	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, parentPose)
		-- 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
						-- create a pose
						for _,v in pairs(script.Parent:GetDescendants()) do
							if v.Name == joint.Name and v:IsA("Motor6D") then
								--rootc = v.Part0.CFrame mot = v
								--local new = Instance.new("Part",workspace) new.Size = Vector3.new(1,2,1) new.Anchored = true new.CanCollide = false new.CFrame = workspace.Native_Clouds.Torso.CFrame*workspace.Native_Clouds.Torso["Left Shoulder"].C0*workspace.Native_Clouds.Torso["Left Shoulder"].C1:Inverse() wait(2) new:Destroy()
								--CFrame.Angles():ToEulerAnglesYXZ()
								--local root0 = CFrame.new(v.Part0.Position)*CFrame.Angles(math.rad(v.Part0.Orientation.X),math.rad(v.Part0.Orientation.Y),math.rad(v.Part0.Orientation.Z))
								local motor6dcframe = v.Part0.CFrame --:ToObjectSpace(v.Part0.CFrame) --*CFrame.Angles(0,math.rad(90),0)
								--local root = CFrame.new(v.Part1.Position)*CFrame.Angles(math.rad(v.Part1.Orientation.X),math.rad(v.Part1.Orientation.Y),math.rad(v.Part1.Orientation.Z))

								local offset
								--if v.Part1:FindFirstChild("offset") == nil then
								offset = (v.Part1.CFrame):ToObjectSpace(motor6dcframe)*(v.C0*v.C1:Inverse())
								
								joint.Transform = offset--CFrame.new(offset.Position)--*offset.Rotation:Inverse()
								break
							end
						end
						local pose
						if preview == nil then
						    pose = Instance.new("Pose")
							pose.Name = connectedPart.Name
							--rightArm.CFrame = rootC * rShoulder.C0 * rShoulder.Transform * rShoulder.C1:Inverse()
							--local rootc,mot=CFrame.new(),CFrame.new()
							--joint.Transform = rootc * mot.C0 * mot.Transform * mot.C1:Inverse()--]]
							pose.CFrame = joint.Transform
							--local transform = (joint.Part0.CFrame*CFrame.new(joint.C0.Position)*CFrame.new(-joint.C1.Position)):ToWorldSpace(joint.Part1.CFrame)
							--pose.CFrame = transform
							parentPose:AddSubPose(pose)
						end
						-- recurse
						addPoses(connectedPart, pose)
					end
				end
			end
		end
	end

	local keyframe = Instance.new("Keyframe")

	-- populate the keyframe
	if preview ~= nil then
		addPoses(rootPart)
	else
		local rootPose = Instance.new("Pose")
		rootPose.Name = rootPart.Name
		addPoses(rootPart, rootPose)
		keyframe:AddPose(rootPose)
	end

	return keyframe
end

local character = workspace:WaitForChild("cframetokeyframe")

game:GetService("RunService").RenderStepped:Connect(function()
	generateKeyframe(character,true)
end)

[Help with Script] Character’s workspace CFrame to Keyframe CFrame - Help and Feedback / Scripting Support - Developer Forum | Roblox

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