Manual animation code acting very weird

I have been interested in script builder games for a very long time so I decided to make one of my own so I made a global animation system where it plays keyframes by lerping motor6Ds and I tested it with a simple walking animation that only involved legs and it have gone fine but I cant find what’s going wrong with this one and I dont see anything in the actual script, can anyone help me?

local module = {}
local playingloopedanimations = {}
function lerp(a, b, t)
	return a + (b - a) * t
end

function CFrameToOrientation(cf)
	local x, y, z = cf:ToOrientation()
	return Vector3.new(math.deg(x), math.deg(y), math.deg(z))
end

function module.PlayAnimation(AnimName,plr,frames)
	local takenmodule = script:FindFirstChild(AnimName)
	local islooped = takenmodule.Loop
	module["HELLO"] = true
	local superogpositions = require(plr.ogposes)
	while module["HELLO"] do
		module["HELLO"] = islooped
			local lastsec = 0
		local frameperframekey = frames
		script.CurrentlyPlaying.Value= AnimName
			for i,v in ipairs(takenmodule:GetChildren()) do
				local truetime = v.Time-lastsec
				for g,n in ipairs(v:GetDescendants()) do
					local thingamajik = plr.Torso:FindFirstChild(n.Name)
					if n.CFrame ~= CFrame.new(0,0,0) then
					local thhh = thingamajik.C0
						if g ~= table.getn(v:GetDescendants()) then
						task.spawn(function()
								for K = 0,1,1/frameperframekey do
								local ASD = lerp(CFrameToOrientation(thhh),CFrameToOrientation(superogpositions[n.Name]*n.CFrame),K)
								local thingish = lerp(thhh.Position, (superogpositions[n.Name]*n.CFrame).Position,K)
								thingamajik.C0 = CFrame.new(thingish) * CFrame.Angles(math.rad(ASD.X), math.rad(ASD.Y), math.rad(ASD.Z))
								if module["HELLO"] == false and islooped then
										break
									end
									task.wait(truetime/frameperframekey)
								end
							end)
						else
							for K = 0,1,1/frameperframekey do
							local ASD = lerp(CFrameToOrientation(thhh), CFrameToOrientation(superogpositions[n.Name])+CFrameToOrientation(n.CFrame),K)
							local thingish = lerp(thhh.Position, superogpositions[n.Name].Position+n.CFrame.Position,K)
							thingamajik.C0 = CFrame.new(thingish) * CFrame.Angles(math.rad(ASD.X), math.rad(ASD.Y), math.rad(ASD.Z))
								task.wait(truetime/frameperframekey)
								if module["HELLO"] == false and islooped then
									break
								end
							end
						end

					end
				end
				lastsec=v.Time
			end
	end
	script.CurrentlyPlaying = nil
end
return module

this is what happens when the animation is played https://gyazo.com/8deb2b76979987f31c7cfec9051045a1

this is what is SUPPOSED to happen

https://gyazo.com/d4e802700dc5430f72c3773718ed3c39

I dont know why this doesnt work, yes the script is hard to look at but please help me on what causes it

(every motor6d is gathered inside the torso (not attached, just in it as parent) the ogpos module takes every motor6d’s first position so it can calculate the supposed locations with the give keyframe locations)

CFrame.Anglles is not orientation the xyz order is different. Use CFrame.fromOrientation instead or just use the rotation CFrame.Rotation no need to orientation back and forth just use the rotation property already in it.

only the hands are going weird nothing else so I dont think that is the problem but I will make sure to try it out later

(lerp only accepts vector3s so I had to transform them to vector3s btw)

CFrame should already have a built in lerp function, I believe its actually slerp (spherical linear interpolation) built in perhaps thats the issue.

Source

1 Like

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