- Home /
Character Animation idle
how can I get my character to default "idle" when nothing else is being pushed?? Here's my code... sorry its sloppy.
<br> var speed = 3.0; var rotateSpeed = 3.0; function Update () { var controller : CharacterController = GetComponent(CharacterController);</p> <pre><code>//Rotate around y - axis transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0); //Move Forward / Backward var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed * Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed); if(Input.GetAxis("Vertical")){ animation.CrossFade("walk"); } if(Input.GetAxis("Horizontal")){ animation.CrossFade("walk"); </code></pre> <p>} function Start () { animation.Stop(); animation.Play("idle"); animation.wrapMode = WrapMode.Loop;</p> <pre><code>animation["run"].layer = -1; animation["walk"].layer = -1; animation["idle"].layer = -2; animation.SyncLayer(-1); var attack = animation["attack"]; attack.wrapMode = WrapMode.Once; animation.Stop(); animation.Play("idle"); </code></pre> <p>}</p> <p>@script RequireComponent(CharacterController)
Wait I did both of those scripts... do I make a new one or add on to the original script?
Answer by mbreen · Sep 13, 2010 at 10:05 PM
Just use a simple if statement to see if the character is moving or not. If the speed is less than 0.1 then play the idle animation.
if (Mathf.Abs(Input.GetAxis("Vertical")) <= 0.1){
animation.CrossFade("Idle");
}
Thanks, that worked great. Even worked for 3d with one addition: if ($$anonymous$$athf.Abs (Input.GetAxis("Vertical") + Input.GetAxis("Horizontal")) <= 0.1) { anim.Play("Idle"); } else { anim.Play("Run"); }
Answer by Will 7 · Sep 13, 2010 at 09:25 PM
Just add
if (!animation.isPlaying){
animation.Play("idle");
}
to your function update.
Answer by dsdsds123100 · May 23, 2012 at 10:25 PM
thank you so much iv ben stuck for a moth on idle animation i love you thank you thank you thank you so so so so so so much
Your answer
![](https://koobas.hobune.stream/wayback/20220613073138im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player is running just few seconds 0 Answers
plz help how do i script/code this line 1 Answer
qrest system 1 Answer
Unity does not recognize reload animation for gun 1 Answer
Add animation curve through script 2 Answers