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
1
Question by Chobi77 · Sep 04, 2012 at 04:38 PM · c#animationjumptransitionwalk

Transition from jump to walk animation.

Hi all,

I am recreating level 1-1 of Super Mario Bros in unity and am using tk2d for the sprite management and c# for scripting.

I have the stage setup and am currently animating Mario who is being controlled by a character controller.

He can idle left and right, walk left and right, run left and right and jump left and right.

My problem is when i jump left or right the jump animation plays (Mario with his fist up) but when i land on the ground the animation does not switch to the walk or run animation instead it keeps the jump animation and just slides along the ground until i let go of the direction button then Mario returns to his idle pose and then if i hit the left or right direction button he will walk as normal.

I am unsure how to solve this transition from jump animation to walk/run animation.

Here is the code i am using for the walk and jump animations.

 //Walk to the left.
 if (Input.GetKeyDown(KeyCode.A))
 {
    velocity *= walkSpeed;
    anim.Play("MarioSmallWalkLeft");
 }

 //Walk to the right.
 if (Input.GetKeyDown(KeyCode.D))
 {
    velocity *= walkSpeed;
    anim.Play("MarioSmallWalkRight");
 }


 //Jump.
 if (Input.GetButtonDown("Jump")
 {
    velocity.y = walkJump;
 }

 //Jump left animation.
 if (velocity.y > 0 && moveDirection == 0)
 {
    anim.Play("SmallMarioJumpLeft");
 }

 //Jump right animation.
 if (velocity.y > 0 && moveDirection == 1)
 {
    anim.Play("SmallMarioJumpRight");
 }

moveDirection 0 and 1 are for determining whether Mario is facing left or right.

Any help would be much appreciated.

Thanks.

Comment
Add comment · Show 2
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 AlucardJay · Sep 04, 2012 at 04:41 PM 0
Share

perhaps you could check if the player is grounded, then check if a 'Small$$anonymous$$arioJump' animation is playing, if it is not playing or has stopped playing then play/crossfade the Idle animation =]

avatar image Chobi77 · Sep 04, 2012 at 06:09 PM 0
Share

Thanks for the reply. :)

I have been messing around with what you said trying to figure out how to make it work.

The problem i see is that $$anonymous$$ario has to be grounded to jump and he is grounded again when he lands on that second grounded the animation needs to switch, but i don't know how to switch the animation and distinguish between the two different times when $$anonymous$$ario is on the ground.

I found the Play$$anonymous$$ode.StopAll which can be used in animation, but i could not get it to work.

And i just found animation.Stop() perhaps if i put that with the jump animation and an if(!controller.isGrounded && velocity.y < 0) it will stop the animation and then i could use the walk animation.

Anyway i buggered it's 4:10am and i think i will sleep on it and tackle the problem again when i get up.

Thanks again for the help and if you or anyone else has any other suggestions please feel free. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by drizztmainsword · Sep 04, 2012 at 10:39 PM

I would distinguish moving on the ground and moving in the air more.

 if (Input.GetKey(KeyCode.D))
 {
    // Set velocity to the right
    // Set moveDirection
 }
 
 if (Input.GetKey(KeyCode.A))
 {
    // Set velocity to the left
    // Set moveDirection
 }
 
 if (controller.isGrounded)
 {
   // Animations for walking
 }
 else
 {
    //In air animations.
 }
Comment
Add comment · Show 2 · 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 Chobi77 · Sep 05, 2012 at 05:34 PM 0
Share

Hi Taylor,

Thanks for the info it is most useful. :)

I put this in a else statement outside of my if (controller.isGrounded) statement.

if (!controller.isGrounded && velocity.y > 0 && moveDirection == 0) { anim.Play("Small$$anonymous$$arioJumpLeft"); } else if (moveDirection == 0) { anim.Play("$$anonymous$$arioSmallWalkLeft"); }

if (!controller.isGrounded && velocity > 0 && moveDirection == 1) { anim.Play("Small$$anonymous$$arioJumpRight"); } else if (moveDirection == 1) { anim.Play("$$anonymous$$arioSmallWalkRight"); }

So far the results are much better, $$anonymous$$ario now lands and walks/runs, the problem now is that he will only play the jump animation on the way up, not on the way up and the way down like he is supposed to.

Any idea's?

avatar image drizztmainsword · Sep 05, 2012 at 05:40 PM 0
Share

The reason for that is you are checking to see if the velocity of $$anonymous$$ario is positive, or moving up.

You should be able to get away with just checking to see if $$anonymous$$ario is on the ground and his moveDirection value.

Also, having else statements after the above statements are redundant. I looked at your code again, and what you want to do is separate the inputs from the animations. I've edited my post with a better breakdown.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

try to make my own character control with animation like- running, walk, idle. So need help and guideline how to do or start 0 Answers

How can ı activate my jump script only at animation 0 Answers

3d Animated Jump Script 0 Answers

How to fluently transition into an animation state? 0 Answers

How do I make it so I can hold down w and shift and it makes an transition to my running animation and when I let go it stops the animation 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