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

How do I make a jumping animation work?

Asked by 3 years ago
Edited 3 years ago

I'm making a game where the character is 2D animated instead of 3D. Actions like walking, dying, jumping etc will change the pose of the 2D character.

Unfortunately, jumping hasn't worked at all for me at all. Here is the code:

local animbody = script.Parent.HumanoidRootPart.BodyUI --The 2D animated rig
local humanoid = script.Parent.Humanoid

humanoid.Running:connect(function(speed) -- Return value; speed of the running
        if speed > 0 then
            animbody.ImageLabel.Image = "rbxassetid://"..6811778352 --Changes to running pose when speed is greater than 0
            animbody.ImageLabel.Size = UDim2.new(0.6,0, 0.691, 0)
    elseif speed == 0 then
            animbody.ImageLabel.Image = "rbxassetid://"..6811242425 --Changes to idle pose when speed is 0
            animbody.ImageLabel.Size = UDim2.new(0.578, 0,0.691, 0)
        end
end)

local isJumping = false

humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        isJumping = true
        animbody.ImageLabel.Image = "rbxassetid://"..6811706850
        animbody.ImageLabel.Size = UDim2.new(0.578, 0,0.696, 0)
    elseif newState == Enum.HumanoidStateType.Landed then
        isJumping = false
        animbody.ImageLabel.Image = "rbxassetid://"..6811242425
        animbody.ImageLabel.Size = UDim2.new(0.578, 0,0.691, 0)
    end
end)

humanoid.Died:connect(function()
    local charParts = script.Parent:GetChildren()

    for i, objects in ipairs(charParts) do
        if objects:IsA("Part") then
            objects.Anchored = true
        end
    end
    animbody.ImageLabel.Image = "rbxassetid://"..6821697622 --Changes to death pose when speed is 0
    animbody.ImageLabel.Size = UDim2.new(0.578, 0,0.691, 0) 
end)

Answer this question