Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
This question was closed Mar 03 at 01:02 AM by jmelendezartist for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by jmelendezartist · Jan 30 at 02:02 AM · jumpinganimations

jump animation stays while pressing arrow keys until I release the arrow keys

So I've been playing with these for the passed few days and I just can not figure it out. When I jump and use the left or right arrow keys and hold it as I land on ground the jump animation stays on and it moves back and forth in the jump animation until I release the arrow keys and the run animation or idle takes effect. alt text

private Rigidbody2D rb; private bool moveLeft; private bool moveRight; private float horizontalMove; public float speed = 15; public float jumpSpeed = 5; public bool isGrounded; bool canDoubleJump; public float delayBeforeDoubleJump; playerControlAI player;

 public  Vector2 left;
 public  Vector2 right;
 
 public Transform groundCheck;
 public float groundRadius = .2f;
 public LayerMask ground; 
 Animator anim;
 public GameObject attackBox;
 public bool attacking;
  
 
     // Start is called before the first frame update
     void Start()
     {
         Animator anim = GetComponent<Animator>();
         rb = GetComponent<Rigidbody2D>();
  
         moveLeft = false;
         moveRight = false;
     }
  
     //I am pressing the left button
     public void PointerDownLeft()
     {
         moveLeft = true;
     }
  
     //I am not pressing the left button
     public void PointerUpLeft()
     {
         moveLeft = false;
     }
  
     //Same thing with the right button
     public void PointerDownRight()
     {
         moveRight = true;
     }
  
     public void PointerUpRight()
     {
         moveRight = false;
     }
   //Same thing with the right button
     public void PointerDownAttack()
     {
         attacking=true;
        attackBox.SetActive(true);
     }
  
     public void PointerUpAttack()
     {
          attacking=false;
         attackBox.SetActive(false);
     }
  
     // Update is called once per frame
     void Update()
     {
         MovementPlayer();
          isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, ground);
 
    if (Input.GetKeyDown(KeyCode.LeftArrow)){
        
              moveLeft = true;
             transform.localScale  = left;
                 
     }
    if (Input.GetKeyUp(KeyCode.LeftArrow)){
 
            moveLeft = false;
     }
    if (Input.GetKeyDown(KeyCode.RightArrow)){
     
            transform.localScale  = right;
            moveRight = true;
               
 }
    if (Input.GetKeyUp(KeyCode.RightArrow)){
 
              moveRight = false;
 }
 
    if (Input.GetKeyDown(KeyCode.Space)&& isGrounded){
 
              jumpButtonDown();
 }
 
 ///==============================================================
 
 if(isGrounded == true){
        
             isGrounded = true;
             canDoubleJump = false;
         }
  if(isGrounded == false){   
           anim.SetInteger("State", 3);
  }
  if(attacking == true){
            anim.SetInteger("State", 5);
 
  }
  if (moveLeft ==true && isGrounded == true)
         {
             anim.SetInteger("State", 2); 
          
         }
          
        
  if (moveRight == true && isGrounded == true)
         {
            anim.SetInteger("State", 2);  
  
         }
  
 
     }
  
     //Now let's add the code for moving
     private void MovementPlayer()
     { 
          anim=GetComponent<Animator>();
          anim.SetInteger("State", 2);
           
          
         //If I press the left button
         if (moveLeft)
         {
             horizontalMove = -speed;
           
          
         }
          
         //if i press the right button
         else if (moveRight)
         {
             horizontalMove = speed;
  
         }
  
         //if I am not pressing any button
         else
         {
              anim.SetInteger("State", 0);
             horizontalMove = 0;
         }
     }
     
     public void jumpButtonDown()
     {
         if(isGrounded)
         { 
             isGrounded = false;
             rb.velocity = Vector2.up * jumpSpeed;
            
             Invoke("EnableDoubleJump", delayBeforeDoubleJump);
         }
         if (canDoubleJump)
         {
 
             rb.velocity = Vector2.up * jumpSpeed;
             canDoubleJump = false;
             
         }
     }
 
     void EnableDoubleJump()
         {
             canDoubleJump = true;
             
         }
  
     //add the movement force to the player
     private void FixedUpdate()
     {
         rb.velocity = new Vector2(horizontalMove, rb.velocity.y);
     }
 }


screen-shot-2022-01-29-at-90106-pm.png (453.4 kB)
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

  • Sort: 
avatar image
0

Answer by jmelendezartist · Mar 03 at 01:00 AM

I solved this by switching animation from State to SetBools.

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

Follow this Question

Answers Answers and Comments

181 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

vibrating jumps and collisions 0 Answers

Touch control swipe up to jump 1 Answer

My game seems to be running too fast for certain tasks 0 Answers

problem with jump script 2 Answers

Help please! Why can't I reduce the speed before jumping? 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