• 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 SML12345 · Jan 29, 2014 at 12:07 PM · animationjavascriptloop animaiton

Animation looping help

Hi, I was making some weird horse game for my sister that included a few animations. I have a script for each animation so that it will play on KeyDown. E.g. when you press W the horse moves forwards and plays the walk animation, spacebar makes it jump and play the jump animation. The script I'm using is this:

 #pragma strict
  function Update()
 {
  if(Input.GetKeyDown("w"))
  {

   animation.Play("run");

  }
 }     


I don't know how I can make this work, but when I press for example, the spacebar, the horse jumps and plays the jump animation fine, but then continues to play the jump animation until another key is pressed. How can I make the animation only play once? Also, I want the walk animation to play only while I hold down the W key and when I'm not holding it down, the horse should revert to the idle animation. Any help greatly appreaciated!!

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 sethuraj · Jan 29, 2014 at 01:16 PM 0
Share

Check for grounding of character.If you are using character controller,you can use IsGrounded in charactercontroller to check whether the horse capsule collider touched the ground or not.If it is grounded play idle animation or use logic like -No keys pressed and character grounded,play idle animation.Its a matter of logic to define states of the player.Walk,Run,Idle,Jump etc

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by OtsegoDoom · Jan 29, 2014 at 03:00 PM

For the jump animation looping (depending on what animation system you're using) double check that the Wrap Mode is not set to loop or that Loop Time is unchecked. That will ensure the animation only plays once and then stops at the end.

Sethuraj's comment above is will get your player to stop running when you're not holding down W.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

In-depth Animation and Audio guide for Enemy AI? 1 Answer

Why my animation clips are disabled? 0 Answers

2D character animation walk left and right 2 Answers

The problem of Enemy scale when he follow the player (script) . How to fix? 0 Answers

Animation won't work. This error is givenn 1 Answer


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