Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SweetRevenge · Sep 13, 2010 at 06:51 PM · animation

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)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FainterStreaker · Jul 25, 2014 at 05:46 AM 0
Share

Wait I did both of those scripts... do I make a new one or add on to the original script?

3 Replies

· Add your reply
  • Sort: 
avatar image
2

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");
    }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · May 21, 2015 at 03:41 AM 0
Share

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"); }

avatar image
0

Answer by Will 7 · Sep 13, 2010 at 09:25 PM

Just add

if (!animation.isPlaying){
    animation.Play("idle");
}

to your function update.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges