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

Animation doesn't show up immideatly after being changed trough script?

Asked by 3 years ago

Hi there, thanks for checking.

Introduction

I'm trying to make a crouch feature in my game by changing the player's default Walk, Run, and Idle animation into a custom animation that I have made.

Problem

I managed to change the default animation, but the change is not visible if the player doesn't stop the currently playing animation. For example, if a player was to press the crouch button while running, the player would still be running with the normal animation until they release 'W' (or fall or anything as long as they stop the current animation), and only then if they press 'W' again would they use the crouch walking animation. Here is the script that I'm using.

01local UIS = game:GetService("UserInputService")
02local character = script.Parent
03local humanoid = character:WaitForChild("Humanoid")
04local hrp = character:WaitForChild("HumanoidRootPart")
05local isCrouching = false
06local defaultWalkSpeed = 16
07local defaultJumpPower = 13
08 
09local deb = false
10 
11local StandToCrouchNoLegs = humanoid:LoadAnimation(script:WaitForChild("StandToCrouchNoLegs"))
12local StandToCrouch = humanoid:LoadAnimation(script:WaitForChild("StandToCrouch"))
13local CrouchWalkAnim = humanoid:LoadAnimation(script:WaitForChild("CrouchWalkAnim"))
14local animateScript = character:WaitForChild("Animate")
15local defaultWalkAnim = animateScript.walk.WalkAnim.AnimationId
View all 64 lines...

I couldn't come up with anything to solve this problem. I imagine it would require me to Reload animation (if that exist). Anyway, thank you for reading, a help would be greatly appreciated.

0
One method I could come up with is changing humanoid's state, this will update his animations, the shortest lasting state is Landed but since it does not last 0 seconds you will see little animation for 0.1 seconds there, here is the code: https://gist.github.com/kirdaaa/2f04c1448e83d8c0a36ffe9b9b967346 imKirda 4491 — 3y
0
A second solution does not require modifying the script, if in animation editor you make that the animation animates ALL the body parts, it will override any other animations, see here: https://i.imgur.com/1goW0d9.png (look at the -0.001 transformations, this is so it thinks that it's animation, if it would be 0 it would be ignored, you need to do that for every limb) imKirda 4491 — 3y
0
I think i did animated all body parts, but i will check it again. iMazariuz 36 — 3y
0
Btw there's no need for stand to crouch anim to be stopped because it's only an animation that i made to transition from standing to crouching and it doesn't loop iMazariuz 36 — 3y

Answer this question