#Animation help

1 messages · Page 1 of 1 (latest)

craggy phoenix
#

Hi, I'm a beginner game developer and I need help with a movement animation issue. I’ve created custom animations for walking and sprinting. When I start the game, the walking animation works correctly. When I press Shift, the sprint animation also plays as intended.
However, after sprinting, the walking animation becomes glitched or stops working properly until I reset the character or the game.

To change the default walking animation, I modified the existing animation script in the game. For sprinting, I created a new script that looks like this:

local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local runningAnimation = Instance.new("Animation")
runningAnimation.AnimationId = "rbxassetid://136014078144391"
local runningTrack = humanoid:LoadAnimation(runningAnimation)

local walkSpeed = 10
local runSpeed = 25
local isRunning = false

UIS.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
        isRunning = true
        humanoid.WalkSpeed = runSpeed
    end
end)

UIS.InputEnded:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        isRunning = false
        humanoid.WalkSpeed = walkSpeed
    end
end)

RunService.RenderStepped:Connect(function()
    local velocity = humanoidRootPart.Velocity

    if isRunning == true and velocity.Magnitude > 1 then
        if not runningTrack.IsPlaying then
            runningTrack:Play()
        end
    else
        if runningTrack.IsPlaying then
            runningTrack:Stop()
        end
    end
end)

I would appreciate it if someone could help me

craggy phoenix
#

Uhh it seems I forgot to delete this line after one of my repair attempts

mental veldt
#

are you not parenting the animation instance

craggy phoenix
sharp raptorBOT
#

studio** You are now Level 1! **studio

craggy phoenix
#

Can I maybe record the result and drop here?

mental veldt
#

actually

#

im wrong

craggy phoenix
#

oh okay

mental veldt
#

ignore me

#

i reread the script

craggy phoenix
#

I'm sorry if it's difficult to understand the script

mental veldt
#

oh no i just read it wrong

craggy phoenix
#

Okay

analog rose
#

you should not use the RunService, to play the animation of running

#

and the problem is that you are using the default Animate, for the walking

craggy phoenix
#

So it means that I need to make a new script for walking animation too?

mental veldt
#

you can use the animate script for walking or any animations

#

why not

analog rose
#

cuz it sucks

mental veldt
#

why does it suck

craggy phoenix
#

I'm confused right now

merry flax
#

U were saying the walking animation becomes glitched? In the video it looks fine when u stop running or am I missing something

craggy phoenix
#

The animation doesn't look the same as it did at the beginning

merry flax
#

Hmm, is it sped up or something? I can’t really tell how it’s different since I’m on my phone

craggy phoenix
#

I would say that it looks like both animations mixed up but it should be impossible because the run animation is stopped

merry flax
#

U could try removing the animation from the animate script and setting on property changes event for the velocity of humanoid root part and then play either walking or running depending on if ur is running variable is true or false

#

So if velocity is more than 0 and is running variable is true stop the walking and play running, if false try to stop the running and play walking, and if velocity is 0 then try to stop both

sharp raptorBOT
#

studio** You are now Level 1! **studio

craggy phoenix
#

Alright, I'll try

analog rose
# mental veldt why does it suck

If you change the animation ID, for some reason that i don't know, it starts doing some weird things. I went through the exact same problem. The solution was simply to remove the default Roblox ID from both the walk and the run, and simply make my own.

sharp raptorBOT
#

studio** You are now Level 2! **studio

craggy phoenix
#

Thank you all for your help

#

Never using "animate" script ever again

#

Am I supposed to somehow close this post or something?

analog rose
sharp raptorBOT
#

studio** You are now Level 4! **studio

mental veldt
#

i suppose its easy to make your own though

#

do you check if velocity == 0 for a idle animation

#

and if velocity is >=1 walk animation