How do i play animation when my player is moving
i am using a touch joystick and i don't know how to play my walking animation when i move my player with the joystick
Answer by Etherpod · Jun 30, 2021 at 07:00 PM
In the animator window, create a bool called "isRunning" or something, you can call it whatever. Click on the transition arrow between the starting animation and the running animation, and at the bottom under parameters, add the "isRunning" bool to it. Next, go into the player script, and in your running function, create a bool called "playerHasHorizontalSpeed" (or something like that) and set it to this... bool playerHasHorizontalSpeed = Mathf.Abs(GetComponent<Rigidbody>().velocity.x) > Mathf.Epsilon;
Make sure to say "Rigidbody2D" if you're doing a 2D game. This says that if the rigidbody's speed is greater than Mathf.Espilon (basically 0), then you're moving. Now, you can say GetComponent<Animator>().SetBool("isRunning", true)
which will start the running animation. Hope I explained this well! Also I just realized this is from 2 years ago...
Sorry if this doesn't work...
Your answer
![](https://koobas.hobune.stream/wayback/20220612182507im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GetButtonDown for joystick? 1 Answer
Detect player movement 0 Answers
Gamepad recognized as joystick and doesn't work 0 Answers
Animator: multiple characters and one script 0 Answers
Cannot get InControl to work 0 Answers