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 /
avatar image
0
Question by Matthias1590 · Oct 27, 2019 at 09:54 PM · animationunity 2d

Jump and fall animations not working

Hey there, I just made a game with some jump and fall animations but they won't work it looks to me like they are repeating themselves before they're finished. I unchecked any loop options and also unchecked can transition to self, my code is working fine I'm sure about that but it might be something with Animator tab settings? I have no clue, can someone help me?

Video of gametesting: https://youtu.be/sFkROilMR0c

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kristifor_p · Oct 27, 2019 at 11:35 PM

Okay i have seen your test video, and yeah you didn't set up your animator correctly.


  1. You need to make transition to your jump animation from any state.

  2. Make sure you added transition to true when you click specific button correctly in your script, if you have it please share it so i can review it.

  3. Make sure the transition time is 0 between animations in 2D games.


Follow this steps and let me know if they worked for you!

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

Answer by Matthias1590 · Oct 28, 2019 at 07:22 AM

@Kristifor_p Thank you for replying! But it's not working yet. it shows me something, but it's still repeating the first frame or something I made a new video: https://youtu.be/wtq4s7nqM58 (the framerate is just timed badly so when you see it fall it flashes between the animations real quick and when u don't see it fall it's just timed so u only get to see the not falling flashing parts)

Here is my script: (The PlayerGroundController script is just a script with a separate collider on my characters feet to see whether I should be able to jump or not)

 public Rigidbody2D rb;
 public float movementSpeed = 1f;
 public float shootingDelay;
 public float jumpHeight = 1f;
 public Animator Animator;
 bool canShoot;
 bool jump;
 public static float direction = 1f;
 public float shootT;
 public float prevY;
 public float newY;
 public bool isFalling;
 public bool isJumping;
 float isFallingToggleT;
 float isJumpingToggleT;

 void FixedUpdate()
 {
     if (jump == true)
     {
         rb.AddForce(new Vector2(0, Time.deltaTime * jumpHeight), ForceMode2D.Impulse);
         jump = false;
     }
 }

 void Update()
 {
     isFallingToggleT += Time.deltaTime;
     isJumpingToggleT += Time.deltaTime;
     shootT += Time.deltaTime;

     if (Input.GetKeyDown(KeyCode.Space) && PlayerGroundController.canJump == true)
     {
         jump = true;
     }

     Animator.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
     transform.position += new Vector3(Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed * 1.5f, 0, 0);

     transform.localScale = new Vector3(direction * 0.2f, 0.2f, 1);

     if (Input.GetKey("a") && Input.GetKey("d") == false)
     {
         direction = -1;
         Animator.SetBool("isShooting", false);
         Animator.Play("blend_tree");
     }

     if (Input.GetKey("d") && Input.GetKey("a") == false)
     {
         direction = 1;
         Animator.SetBool("isShooting", false);
         Animator.Play("blend_tree");
     }

     if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.15)
     {
         Animator.speed = 2.25f;
     } else {
         Animator.speed = 1f;
     }

     if (shootT > 1)
     {
         Animator.SetBool("isShooting", false);
         Animator.Play("blend_tree");
     }

     if (Input.GetKey("j") && shootT > shootingDelay && Input.GetAxis("Horizontal") == 0 && PlayerGroundController.canJump == true)
     {
         Animator.SetBool("isShooting", true);
         Animator.Play("player_shooting");
         shootT = -0.25f;
         canShoot = true;

         if (shootT > shootingDelay + 0.1)
         {
             Animator.SetBool("isShooting", false);
         }
     }

     if (shootT > 0 && canShoot == true)
     {
         GunScript.shoot = true;
         canShoot = false;
     }

     newY = transform.position.y;

     if (newY < prevY)
     {
         Animator.SetBool("isFalling", true);
         isFalling = true;
         isFallingToggleT = 0;
     } else {
         if (isFallingToggleT > 0.1)
         {
             isFalling = false;
             Animator.SetBool("isFalling", false);
         }
     }

     if (newY > prevY)
     {
         Animator.SetBool("isJumping", true);
         isJumping = true;
         isJumpingToggleT = 0;
     } else {
         if (isJumpingToggleT > 0.1)
         {
             isJumping = false;
             Animator.SetBool("isJumping", false);
         }
     }

     prevY = newY;
 }

}

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

295 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 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

2D Animation.Play does no effect 1 Answer

Blender 3d animation to Unity 2d animation 2 Answers

I have an animated character that's going to ride a bike, but how do I put one leg behind and one leg in front of the bike in Unity 2D? 1 Answer

issue using OverlapCircle and AnyState in Unity Animator,issue using OverlapCirlce and AnyState in Unity Animator 0 Answers

Import swf into unity 2d 4 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