Search code examples
luarobloxfbx

Roblox How to make a player with fbx model? And animate?


I was able to import the FBX model in Roblox Studio and even animate it, but this Humanoid cannot climb stairs and the animation has a 1 second delay. I need to remove this delay, teach him to climb stairs and jump with animation.

Animate script on tree, Humanoid model and animation

Here is the animation script

model = script.Parent
Humanoid = model:WaitForChild("Humanoid")
RunService = game:GetService("RunService")

Humanoid:ChangeState(Enum.HumanoidStateType.None)

idleAnimation = script:WaitForChild('idle');
walkAnimation = script:WaitForChild('walk');
runAnimation = script:WaitForChild('run');
jumpAnimation = script:WaitForChild('jump');

Pose = "none"
LastPose = Pose
PoseTime = tick()

ToolAnimTime = 0

local animation: AnimationTrack = nil;
function playAnim(anim)
    if animation ~= nil and animation.IsPlaying then
        --print(animation.Animation.Name, ' == ', anim.Name, ' = ', animation.Animation.Name == anim.Name)
        if animation.Animation.Name == anim.Name then
            return;
        end
        
        animation:Stop();
    end
    
    print('playAnim ', anim.Name)
    
    animation = Humanoid:LoadAnimation(anim)
    animation.Looped = false
    animation:Play()
end

function SetPose(pose)
    LastPose = Pose
    Pose = pose
    PoseTime = tick()
end

function OnRunning(Speed)
    if Speed > 0 then
        SetPose("Running")
    else
        SetPose("Standing")
    end
end

function OnDied()
    SetPose("Dead")
end

function OnJumping()
    SetPose("Jumping")
end

function OnClimbing()
    SetPose("Climbing")
end

function OnGettingUp()
    SetPose("GettingUp")
end

function OnFreeFall()
    SetPose("FreeFall")
end

function OnFallingDown()
    SetPose("FallingDown")
end

function OnSeated()
    SetPose("Seated")
end

function OnPlatformStanding()
    SetPose("PlatformStanding")
end

function OnSwimming(Speed)
    return OnRunning(Speed)
end

function MoveFreeFall()
    --RightShoulder.MaxVelocity = 0.15
    --LeftShoulder.MaxVelocity = 0.15
    --RightShoulder.DesiredAngle = 0.5
    --LeftShoulder.DesiredAngle = -0.5
    --RightHip.DesiredAngle = -0.5
    --LeftHip.DesiredAngle = 0.5
end

function MoveSit()
    --RightShoulder.MaxVelocity = 0.15
    --LeftShoulder.MaxVelocity = 0.15
    --RightShoulder.DesiredAngle = (math.pi / 2)
    --LeftShoulder.DesiredAngle = -(math.pi / 2)
    --RightHip.DesiredAngle = 1
    --LeftHip.DesiredAngle = -1
end


function Move()
    if (Pose == "Jumping") then
        playAnim(jumpAnimation)
        return
    elseif (Pose == "FreeFall") then
        MoveFreeFall()
        return
    elseif (Pose == "Seated") then
        MoveSit()
        return
    end

    local ClimbFudge = 0

    if (Pose == "Running") then
        playAnim(runAnimation);
    elseif (Pose == "Climbing") then
        playAnim(jumpAnimation);
    else
        playAnim(idleAnimation);
    end

end

Humanoid.Died:connect(OnDied)
Humanoid.Running:connect(OnRunning)
Humanoid.Jumping:connect(OnJumping)
Humanoid.Climbing:connect(OnClimbing)
Humanoid.GettingUp:connect(OnGettingUp)
Humanoid.FreeFalling:connect(OnFreeFall)
Humanoid.FallingDown:connect(OnFallingDown)
Humanoid.Seated:connect(OnSeated)
Humanoid.PlatformStanding:connect(OnPlatformStanding)
Humanoid.Swimming:connect(OnSwimming)
RunService.Stepped:connect(Move)

I was able to import the model, import the animation, but now there is a problem with the script, the game has a delay of 1 second.


Solution

  • I had a delay per second due to the fact that the script was server-side, I thought that if you make the script local, then other players will not see the animation of the current player, but it turns out they will. So I just made the server script a local script.