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

Sword Rotation gets messed up?

Asked by 8 years ago

The sword Rotation gets messed up when I try to sheathe it while walking. If I sheathe it standing still it works fine like this

https://gyazo.com/74c616449fd7f56b07722bd07e6e3119

But If I walk then the sword rotation gets messed up like this

https://gyazo.com/a608a3b138a900c9a45a952527bac02a

Code:

equipAnim = script.Parent:WaitForChild("EquipAnim5")
idleAnim = script.Parent:WaitForChild("IdleAnim3")
sheatheAnim = script.Parent:WaitForChild("SheatheAnim")
player = game.Players.LocalPlayer
rootPart = player.Character:FindFirstChild("HumanoidRootPart")
equipped = true

rightArm = player.Character:FindFirstChild("Right Arm")
katana = player.Character.Katana


function drawSword(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then
        if equipped then
            equipped = false

            local playEquipAnim = player.Character.Humanoid:LoadAnimation(equipAnim)
            playEquipAnim:Play()

            local oldWeld = katana:FindFirstChild("Weld")

            if oldWeld then
                oldWeld:Destroy()
            end

            katana.CFrame = player.Character:WaitForChild("Right Arm").CFrame * CFrame.new(0, -1, -1.7)
            katana.CFrame = katana.CFrame * CFrame.Angles(59.7, 0, -190)


            local newWeld = Instance.new("Weld")
            newWeld.Name = "Weld"
            newWeld.Part0 = rightArm
            newWeld.C0 = rightArm.CFrame:inverse()
            newWeld.Part1 = katana
            newWeld.C1 = katana.CFrame:inverse()
            newWeld.Parent = katana


            wait(1.1)

            playIdleAnim = player.Character.Humanoid:LoadAnimation(idleAnim)
            playIdleAnim:Play()
        end
    end
end

game:GetService("UserInputService").InputBegan:connect(drawSword)

function sheatheSword(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then   
        if equipped == false then
            local playSheatheAnim = player.Character.Humanoid:LoadAnimation(sheatheAnim)
            playSheatheAnim:Play()

            wait(1.1)

            local equippedWeld = script.Parent:FindFirstChild("Weld")
            if equippedWeld then
                equippedWeld:Destroy()
            end

            katana.CFrame = player.Character:FindFirstChild("Left Leg").CFrame * CFrame.new(-.6, .2, 1.7)
            katana.CFrame = katana.CFrame * CFrame.Angles(.3, 0, 1.5)




            local sheatheWeld = Instance.new("Weld")
            sheatheWeld.Name = "Weld"
            sheatheWeld.Part0 = rootPart
            sheatheWeld.C0 = rootPart.CFrame:inverse()
            sheatheWeld.Part1 = katana
            sheatheWeld.C1 = katana.CFrame:inverse()
            sheatheWeld.Parent = katana

            playIdleAnim:Stop()

            equipped = true 
        end         
    end
end

game:GetService("UserInputService").InputBegan:connect(sheatheSword)

How do I make it so the rotation doesn't get messed up when sheathing while walking?

0
Should I just make it so the player's walkspeed is 0 when equipping and sheathing? NovaMagic 73 — 8y
0
by setting player walkspeed to 0 when sheating sword seems to have fixed it but if anyone knows how to fix it without changing the walkspeed, I'd love to hear it NovaMagic 73 — 8y

Answer this question