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 emilx132 · Sep 19, 2014 at 02:16 PM · animationjavascriptjumpingrunning

Scripting and Animation problems

Hello guys. I need help with some animation and some scripting. I wan't it to run my jump animation when i press space while running or walking. So if im running by pressing W and LeftShift and then wan't to jump then while holding those buttons down i press space to jump. Then i jump but the animation don't play because its running the other animations. It also happens if i walk and press space to jump. It don't play the animation. Only when im standing still or being idle and press space. I would like if u guys could help me with it.

I guess what i need is some kind of a code that checks if im n the air or if im on the ground. Then i need it to say if im in the air it have to pause or stop the walk/run animation and then play the jump animation. Then when im on the ground i wan't it to start the walk/run animation again. of cause if im idle it don't have to play the walk and run animation

This is my script

     #pragma strict
     
     var TheDamage : int = 50;
     var Distance : float;
     var MaxDistance : float = 1.5;
     var TheMace : Transform;
     
     function Update ()
     {
         if (Input.GetButton("Fire1"))
         {
             //Attack animation
             TheMace.animation.Play("Attack");
             //Attack function
             var hit : RaycastHit;
             if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
             {
                 Distance = hit.distance;
                 if (Distance < MaxDistance)
                 {
                     hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
                 }
             }
         } //animation til bevægelse (At gå frem og tilbage med våbnet) og at hoppe.
         
         if (Input.GetButtonUp("Fire1"))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (TheMace.animation.isPlaying == false)
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKey (KeyCode.W))
         {
             TheMace.animation.CrossFade("Walk");
             if (Input.GetKey (KeyCode.LeftShift))
             {
                 TheMace.animation.CrossFade("Sprint");
             }
         }
         
         if (Input.GetKey (KeyCode.A))
         {
             TheMace.animation.CrossFade("Walk");
              if (Input.GetKey (KeyCode.LeftShift))
             {
                 TheMace.animation.CrossFade("Sprint");
             }
         }
         
         if (Input.GetKey (KeyCode.S))
         {
             TheMace.animation.CrossFade("Walk");
              if (Input.GetKey (KeyCode.LeftShift))
             {
                 TheMace.animation.CrossFade("Sprint");
             }
         }
         
         if (Input.GetKey (KeyCode.D))
         {
             TheMace.animation.CrossFade("Walk");
              if (Input.GetKey (KeyCode.LeftShift))
             {
                 TheMace.animation.CrossFade("Sprint");
             }
         }
         
         if (Input.GetKeyUp (KeyCode.LeftShift))
         {
             TheMace.animation.CrossFade("Walk");
         }
         
         if (Input.GetKeyUp (KeyCode.W))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKeyUp (KeyCode.S))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKeyUp (KeyCode.A))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKeyUp (KeyCode.D))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKeyUp (KeyCode.Space))
         {
             TheMace.animation.CrossFade("Idle");
         }
         
         if (Input.GetKeyDown (KeyCode.Space))
         {
             TheMace.animation.CrossFade ("Jump");
         }
     }
 
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 betaFlux · Sep 19, 2014 at 03:39 PM

I don't have the solution to your specific problem, this is just a hint: You can omit all GetKeyUp conditions. To make your character idle, just call your movement and shooting conditions and then you simply put your idle animation somewhere, like so:

 void Update()
 {
    if(Input.GetKeyDown(KeyCode.W))
    {
        animation["walk"].speed = 1;
        animation.CrossFade("walk");
    }
    if(Input.GetKeyDown(KeyCode.S))
    {
        animation["walk"].speed = -1;
        animation.CrossFade("walk");
    }
    animation.CrossFade("idle");
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Fall animation when character is falling 3 Answers

Textured jump animation moving left and right while in the air -help! 1 Answer

Need help with sprite animating 1 Answer

Attack While Running 1 Answer

Run Animation/Jump animation/Scripting Movement/Animations 0 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