Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by Deanford · Aug 22, 2015 at 12:05 AM · mecanim

Unity 2D Mecanim Animation Stutter

Hey, I am getting this animation stutter after I jump, it goes between jump and idle really quickly and doesn't stop... I have tried to set the transition delay to 0 and I have no exit time; so I could get a quick transition, which works for the transitioning times but obviously not with this.

I ha-vent had any errors when in play mode, just that problem^.

Here is the script aswell if you need it:

 public class PlayerControl : MonoBehaviour
   {
       bool grounded, interact; //bool for checking if player is grounded so they can jump, and bool for interact, so that player can only interact when in range of thing to interact with
       public Transform jumpCheck, interactCheck; //transform variable for the end points of the linecasts
   
       RaycastHit2D interacted; //a variable type that stores a collider that was hit during linecast
   
       public float speed = 6.0f;
   
   
       float jumpTime, jumpDelay = .6f;
       bool jumped;
   
       Animator anim;
   
       void Start()
       {
           anim = GetComponent<Animator>();
       }
   
       void Update()
       {
           Movement(); //call the function every frame
           RaycastStuff(); //call the function every frame
       }
   
       void RaycastStuff()
       {
           //Just a debug visual representation of the Linecast, can only see this in scene view! Doesn't actually do anything!
           Debug.DrawLine(transform.position, jumpCheck.position, Color.magenta);
           Debug.DrawLine(transform.position, interactCheck.position, Color.magenta);
   
           //we assign the bool 'ground' with a linecast, that returns true or false when the end of line 'jumpCheck' touches the ground
           grounded = Physics2D.Linecast(transform.position, jumpCheck.position, 1 << LayerMask.NameToLayer("Ground"));  
   
           //Using linecast which takes (start point, end point, layermask) so we can make it only detect objects with specified layers
           //its wrapped in an if statement, so that while the tip of the Linecast (interactCheck.position) is touching an object with layer 'Guard', the code inside executes
           if(Physics2D.Linecast(transform.position, interactCheck.position, 1 << LayerMask.NameToLayer("Guard")))
           {
               //we store the collider object the Linecast hit so that we can do something with that specific object, ie. the guard
               //each time the linecast touches a new object with layer "guard", it updates 'interacted' with that specific object instance
               interacted = Physics2D.Linecast(transform.position, interactCheck.position, 1 << LayerMask.NameToLayer("Guard")); 
               interact = true; //since the linecase is touching the guard and we are in range, we can now interact!
           }
           else
           {
               interact = false; //if the linecast is not touching a guard, we cannot interact
           }
   
           Physics2D.IgnoreLayerCollision(8, 10); //if we want certain layers to ignore each others collision, we use this! the number is the layer number in the layers list
       }
   
   
       void Movement() //function that stores all the movement
       {
           anim.SetFloat("speed", Mathf.Abs(Input.GetAxis ("Horizontal")));
   
           if(Input.GetAxisRaw("Horizontal") > 0)
           {
               transform.Translate(Vector3.right * speed * Time.deltaTime); 
               transform.localScale = new Vector3 (1f, 1f, 1f); //Flip Texture
           }
   
           if(Input.GetAxisRaw("Horizontal") < 0)
           {
               transform.Translate(Vector3.left * speed * Time.deltaTime);
               transform.localScale = new Vector3 (-1f, 1f, 1f); //Flip Texture
           }
   
           if(Input.GetKeyDown (KeyCode.Space) && grounded) // If the jump button is pressed and the player is grounded then the player jumps 
           {
               GetComponent<Rigidbody2D>().AddForce(transform.up * 400f);
               jumpTime = jumpDelay;
               anim.SetTrigger("Jump");
               jumped = true;
           }
   
           jumpTime -= Time.deltaTime;
           if(jumpTime <= 0 && grounded && jumped)
           {
               anim.SetTrigger("Land");
               jumped = false;
           }
   
   
       }
  }
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

0 Replies

· Add your reply
  • Sort: 

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

25 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

Related Questions

Sync Mecanim Trigger over network 1 Answer

Implementing falling: How to maintain forward inertia as I transition into a fall animation? 0 Answers

Mecanim "Hello, World" 0 Answers

Mecanim muscle system overrides T-pose 0 Answers

Make pivot transition in mecanim in a 2.5d game? 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