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 eivhys · Dec 17, 2013 at 09:03 AM · animationjavascriptjumpingspacebar

Need help with sprite animating

OK, so I'm new to unity and me and a friend want to make a 2D game. So I've followed a tutorial on youtube and write this script:

Now, I've done some simple coding and programming before (but never in javascript) and i can understand the code.

With this script the animation changes between walking / jumping / idle (it is connected to this javascript http://wiki.unity3d.com/index.php/Animating_Tiled_texture_-_Extended), but when space (the jump button) is pushed and the sprite jumps, if you keep holding space the character will still be in the jump animation. How c

So here comes the question:

What can I do to make the character change back to the idle animation when hitting the ground (when the player is holding the jump button)?

And can I have another animation for when the character is on his way down?

Note: English is not my first language so I'm sorry that my formulation isn't the best

 #pragma strict
 
 
 
 
 function Start () {
 
 }
 
 function Update () {
     
     var AT = gameObject.GetComponent(AnimateTexture); //Store the AnimateTexture script
 
     if(Input.GetKey("space")) { //Player jumps
         AT.rowNumber = 2; //Start jumping animation
     }
 
     else if(Input.GetKey("a")) { //Player moves left
         AT.rowNumber = 1; //Start running animation
     }
         
     else if(Input.GetKey("d")) { //Player moves right
         AT.rowNumber = 1; //Start running animation
     }
     
     else if(Input.GetKey("left")) { //Player moves left
         AT.rowNumber = 1; //Start running animation
     }
     
     else if(Input.GetKey("right")) { //Player moves right
         AT.rowNumber = 1; //Start running animation
     }
     
 
     
     else { //Player doesn't press anything
         AT.rowNumber = 0; //Return back to the idle animation
     }
     
     
 } 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KellyThomas · Dec 17, 2013 at 10:13 AM

At the moment animation is dependent entirely on input..

Normally animation would depend on character state (walking, jumping, punching etc).

Then you would allow the environment and player input to control character state.

For example:

  • if the character is grounded (known to be on the ground) and the player presses jump then let the character jump (apply vertical movement and play the jump animation).

  • if the character is grounded and the player enters no input play the idle animation.

With these two rules the player will transition idle to and back to idle appropriately..

As you can see the correct animation depends the character state, which is effected by both input and environment.

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

18 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Animation won't start when collision starts 0 Answers

problem not playing animation on keyDown 2 Answers

Animator preventing correct spawn position? 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