so i’ve create this script where it plays animation from a module that is converted from an animation
the script:
local function lerp(a, b, t)
return a + (b - a) * t
end
local AnimationData = require(workspace.F)
local isPlaying = true
local function playAnimation(character, animationData)
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then
return
end
local t = 0
while isPlaying do
for i = 1, #animationData.Keyframes - 1 do
local keyframe1 = animationData.Keyframes[i]
local keyframe2 = animationData.Keyframes[i + 1]
for partName, partData in pairs(keyframe1) do
local part = character:FindFirstChild(partName)
if part then
for propertyName, cframe1 in pairs(partData) do
local cframe2 = keyframe2[partName][propertyName]
for i,v in pairs(character:GetDescendants()) do
if v:IsA("Motor6D") then
while t < 1 do
v.C0 = CFrame.new(
lerp(cframe1.Position, cframe2.Position, t),
lerp(cframe1.Rotation, cframe2.Rotation, t)
)
wait(0.03) -- Adjust this time interval for smoother or faster interpolation
t = t + 0.03
end
end
end
end
end
end
t = 0 -- Reset interpolation time for the next keyframe
wait(keyframe2.Time) -- Wait for the specified time before moving to the next keyframe
end
end
end
local function stopAnimation()
isPlaying = false
end
local character = game.Workspace:WaitForChild("Rig")
playAnimation(character, AnimationData)
and this is the module:
return {
Properties = {
Looping = true,
Priority = Enum.AnimationPriority.Core
},
Keyframes = {
[0] = {
["HumanoidRootPart"] = {
["Torso"] = {
CFrame = CFrame.new(0, 0, 1.719),
},
},
},
[0.333] = {
["HumanoidRootPart"] = {
["Torso"] = {
CFrame = CFrame.new(0, 0, -1.238),
},
},
},
[0.633] = {
["HumanoidRootPart"] = {
["Torso"] = {
CFrame = CFrame.new(0, 0, 1.719),
},
},
},
}
}
the error:
i wanted to use cframe animation module cuz it is easier for me to edit the offset