-- This is actually not his example I lost it but I gave you what I had in my animation script Lerp = function(a,b,c) return a+(b-a)*c end function ctlerp(c1,c2,al) local com1 = {c1:components()} local com2 = {c2:components()} for i,v in pairs(com1) do com1[i] = lerp(v,com2[i],al) end return CFrame.new(unpack(com1)) end do local function QuaternionFromCFrame(cf) local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components() local trace = m00 + m11 + m22 if trace > 0 then local s = math.sqrt(1 + trace) local recip = 0.5/s return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5 else local i = 0 if m11 > m00 then i = 1 end if m22 > (i == 0 and m00 or m11) then i = 2 end if i == 0 then local s = math.sqrt(m00-m11-m22+1) local recip = 0.5/s return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip elseif i == 1 then local s = math.sqrt(m11-m22-m00+1) local recip = 0.5/s return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip elseif i == 2 then local s = math.sqrt(m22-m00-m11+1) local recip = 0.5/s return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip end end end local function QuaternionToCFrame(px, py, pz, x, y, z, w) local xs, ys, zs = x + x, y + y, z + z local wx, wy, wz = w*xs, w*ys, w*zs local xx = x*xs local xy = x*ys local xz = x*zs local yy = y*ys local yz = y*zs local zz = z*zs return CFrame.new(px, py, pz,1-(yy+zz), xy - wz, xz + wy,xy + wz, 1-(xx+zz), yz - wx, xz - wy, yz + wx, 1-(xx+yy)) end local function QuaternionSlerp(a, b, t) local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4] local startInterp, finishInterp; if cosTheta >= 0.0001 then if (1 - cosTheta) > 0.0001 then local theta = math.acos(cosTheta) local invSinTheta = 1/math.sin(theta) startInterp = math.sin((1-t)*theta)*invSinTheta finishInterp = math.sin(t*theta)*invSinTheta else startInterp = 1-t finishInterp = t end else if (1+cosTheta) > 0.0001 then local theta = math.acos(-cosTheta) local invSinTheta = 1/math.sin(theta) startInterp = math.sin((t-1)*theta)*invSinTheta finishInterp = math.sin(t*theta)*invSinTheta else startInterp = t-1 finishInterp = t end end return a[1]*startInterp + b[1]*finishInterp, a[2]*startInterp + b[2]*finishInterp, a[3]*startInterp + b[3]*finishInterp, a[4]*startInterp + b[4]*finishInterp end function clerp(a,b,t) local qa = {QuaternionFromCFrame(a)} local qb = {QuaternionFromCFrame(b)} local ax, ay, az = a.x, a.y, a.z local bx, by, bz = b.x, b.y, b.z local _t = 1-t return QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,QuaternionSlerp(qa, qb, t)) end end function newAni(length,joints) if not joints then error("You didn't give me any joints!") end local ani = {} local ignored = {} ani.keyframes = {} ani.frames = {} ani.looped = false ani.length = length ani.running = false ani.paused = false ani.pauseAt = -1 ani.smoothFactor = 2 function ani:run(sync) local function run() local me = math.random() self.runid = me self.running = true self.paused = false local firstRun = true if self.startModifier then for i,v in pairs(joints) do v.C0,v.C1 = self.startModifier(v,v.C0,v.C1) end end repeat self:updateFrames(not firstRun) firstRun = false local i = 1 while true do self.frame = i if i == self.pauseAt then self.paused = true end for _,v in pairs(self.frames[i]) do if not ignored[v.joint] then local c0 = v.c0 local c1 = v.c1 for a = math.max(1,i-self.smoothFactor),math.min(self.length,i+self.smoothFactor) do if self.frames[a] and self.frames[a][v.joint] then c0 = clerp(c0,self.frames[a][v.joint].c0,1/(2*self.smoothFactor+1)) c1 = clerp(c1,self.frames[a][v.joint].c1,1/(2*self.smoothFactor+1)) end end if v.modifier then c0,c1 = v.modifier(v.joint,c0,c1) end v.joint.C0 = c0 v.joint.C1 = c1 if v.joint:IsA("Motor") then v.joint.DesiredAngle = 0 v.joint.MaxVelocity = 0 v.joint.CurrentAngle = 0 end end end local start = tick() game:GetService'RunService'.RenderStepped:wait() local timetaken = tick()-start local am = math.max(1,math.floor(timetaken/0.01666666666666+.5)) if not self.running or self.runid ~= me then return end if not self.paused then i = i + am if not self.frames[i] then break end end end if not self.looped then self.running = false end until not self.running end if sync then run() else coroutine.wrap(run)() end end function ani:stop() self.running = false end function ani:pause() self.paused = true end function ani:resume() self.paused = false end function ani:pauseAt(index) self.pauseAt = index end function ani:getNextKeyframeFor(joint,index) index = index or 1 for i=index,self.length do if self.keyframes[i] and self.keyframes[i][joint] then return self.keyframes[i][joint] end end return false end function ani:getPrevKeyframeFor(joint,index) index = index or 1 for i=index,1,-1 do if self.keyframes[i] and self.keyframes[i][joint] then return self.keyframes[i][joint] end end return false end function ani:setKeyframe(index,joint,c0,c1,modifier) ani.keyframes[index] = ani.keyframes[index] or {} local prev = ani:getPrevKeyframeFor(joint,index) ani.keyframes[index][joint] = {index=index,joint=joint,c0=c0 or (prev and prev.c0 or joint.C0),c1=c1 or (prev and prev.c1 or joint.C1),modifier=modifier} end function ani:ignoreJoints(tab) ignored = {} for i,v in pairs(tab) do ignored[v] = true end end function ani:updateFrames(isLooped) local prev = {} local oframes = isLooped and #self.frames > 0 and self.frames[#self.frames] or {} self.frames = {} for i=1,self.length do if self.keyframes[i] then for joint,tab in pairs(self.keyframes[i]) do prev[joint] = tab end end local t = {} for _,joint in pairs(joints) do local kbegin = prev[joint] if not kbegin then local wc0,wc1 = oframes[joint] and oframes[joint].c0 or joint.C0,oframes[joint] and oframes[joint].c1 or joint.C1 kbegin = {index=1,c0=wc0,c1=wc1} end local kend = self:getNextKeyframeFor(joint,i) if kend then local am = (i-kbegin.index)/(kend.index-kbegin.index) local lc0 = clerp(kbegin.c0,kend.c0,am) local lc1 = clerp(kbegin.c1,kend.c1,am) if kbegin == kend then lc0 = kend.c0 lc1 = kend.c1 end t[joint] = {joint=joint,index=i,c0=lc0,c1=lc1,modifier=kend.modifier} end end self.frames[i] = t end end return ani end local ani = newAni(32, {RootJoint,LeftHip,RightHip,Neck,RightSH,LeftSH}) ani.looped = true ani:setKeyframe(16,RootJoint,c0.RootJoint*CFrame.new(0,0,0)*CFrame.Angles(-.02,-.1,0),nil,breathe) ani:setKeyframe(16,LeftHip,c0.LeftHip*CFrame.new(0,0,0)*CFrame.Angles(-.4,.05,-.02),nil,breathe) ani:setKeyframe(16,RightHip,c0.RightHip*CFrame.new(0,0,0)*CFrame.Angles(.4,-.05,.02),nil,breathe) ani:setKeyframe(16,LeftSH,c0.LeftSH*CFrame.new(0,0,0)*CFrame.Angles(.5,.05,-.02),nil,breathe) ani:setKeyframe(16,RightSH,c0.RightSH*CFrame.new(0,0,0)*CFrame.Angles(-.5,-.05,.02),nil,breathe) ani:setKeyframe(16,Neck,c0.Neck*CFrame.Angles(-.05,.1*0.8,0),nil,breathe) ani:setKeyframe(32,RootJoint,c0.RootJoint*CFrame.new(0,0,0)*CFrame.Angles(-.02,.1,0),nil,breathe) ani:setKeyframe(32,LeftHip,c0.LeftHip*CFrame.new(0,0,0)*CFrame.Angles(.4,.05,-.02),nil,breathe) ani:setKeyframe(32,RightHip,c0.RightHip*CFrame.new(0,0,0)*CFrame.Angles(-.4,-.05,.02),nil,breathe) ani:setKeyframe(32,LeftSH,c0.LeftSH*CFrame.new(0,0,0)*CFrame.Angles(-.5,.05,-.02),nil,breathe) ani:setKeyframe(32,RightSH,c0.RightSH*CFrame.new(0,0,0)*CFrame.Angles(.5,-.05,.02),nil,breathe) ani:setKeyframe(32,Neck,c0.Neck*CFrame.Angles(-.05,.1*0.8,0),nil,breathe) PossibleActions.Walk=ani end