Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help make my animation (Motor6Ds) run smoother?

Asked by 10 years ago

I'm animating characters through Motor6D. It works pretty smoothly, except for the fact that the animation is pretty choppy at the beginning. I'm using Vector3:Lerp() to make C0s. Could someone make it smoother? I also keep some things in a ModuleScript.

Part of the LocalScript:

repeat wait() until game.Players.LocalPlayer

database = require(Workspace.Database)

repeat wait() until database

player = game.Players.LocalPlayer
character = player.Character
cam = Workspace.CurrentCamera
mouse = player:GetMouse()
humanoid = character.Humanoid

player.CameraMode = "LockFirstPerson"

humanoid.Running:connect(function(speed)
    if speed > 0 then
        running = true
        while running do
            for frame = 1, #database.Frames.Running do
                if not running then break end
                for i = 0,1,0.1 do
                    if not running then break end
                    for joint, start in pairs(database.Frames.Running[frame]) do
                        local lerp = (frame == #database.Frames.Running and Vector3.new(0,0,0) or start):Lerp(database.Frames.Running[frame+1] and database.Frames.Running[frame+1][joint] or Vector3.new(0,0,0),i)
                        character.Torso[joint].C0 = database.Humanoid[joint].C0*CFrame.new(lerp.X,lerp.Y,lerp.Z)
                    end
                    wait()
                end
            end
        end
    else
        running = false
        for i, joint in pairs(character.Torso:GetChildren()) do
            if joint:IsA("Motor6D") then
                character.Torso[joint.Name].C0 = database.Humanoid[joint.Name].C0
            end
        end
    end
end)

Part of the ModuleScript:

database = {}


database.Frames = {}
database.Frames.Running = {}

database.Frames.Running = {
    {
        ["Right Shoulder"] = Vector3.new(0.1,-0.1,0),
        ["Left Shoulder"] = Vector3.new(0.1,-0.1,0)             
    };
    {
        ["Right Shoulder"] = Vector3.new(0,0,0),
        ["Left Shoulder"] = Vector3.new(0,0,0)      
    };
    {
        ["Right Shoulder"] = Vector3.new(-0.1,-0.1,0),
        ["Left Shoulder"] = Vector3.new(-0.1,-0.1,0)
    }
}

for animation, frames in pairs(database.Frames) do
    table.insert(frames,{})
    table.insert(frames,1,{})
    for joint, _ in pairs(frames[1]) do
        frames[1][joint] = Vector3.new(0,0,0)
        frames[#frames][joint] = Vector3.new(0,0,0)
    end
    setmetatable(frames,{})
    getmetatable(frames).__index = {Joints = {}}
    for joint, _ in pairs(frames[1]) do
        table.insert(frames.Joints,joint)
    end

end

return database

There's also a place you can check out: http://www.roblox.com/FPS-Testing-place?id=58724430

Answer this question