- Get link
- Other Apps
How to Do Grow Animation Like Mario Unity
- Home /
Transition from leap to walk blitheness.
Hi all,
I am recreating level 1-i of Super Mario Bros in unity and am using tk2d for the sprite direction and c# for scripting.
I have the stage setup and am currently animative Mario who is being controlled by a grapheme controller.
He can idle left and right, walk left and right, run left and correct and spring left and correct.
My problem is when i jump left or right the bound blitheness plays (Mario with his fist upwardly) but when i land on the ground the animation does not switch to the walk or run animation instead information technology keeps the bound animation and just slides along the footing until i let go of the direction button then Mario returns to his idle pose and so if i hit the left or right direction push he will walk as normal.
I am unsure how to solve this transition from spring 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"); } //Leap right blitheness. if (velocity.y > 0 && moveDirection == 1) { anim.Play("SmallMarioJumpRight"); }
moveDirection 0 and 1 are for determining whether Mario is facing left or right.
Whatsoever aid would exist much appreciated.
Thanks.
Answer by drizztmainsword · Sep 04, 2012 at x: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 // Prepare moveDirection } if (Input.GetKey(KeyCode.A)) { // Set velocity to the left // Set up moveDirection } if (controller.isGrounded) { // Animations for walking } else { //In air animations. }
Hello Taylor,
Thanks for the info information technology 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("Minor$$anonymous$$arioJumpLeft"); } else if (moveDirection == 0) { anim.Play("$$anonymous$$arioSmallWalkLeft"); }
if (!controller.isGrounded && velocity > 0 && moveDirection == 1) { anim.Play("Modest$$bearding$$arioJumpRight"); } else if (moveDirection == 1) { anim.Play("$$bearding$$arioSmallWalkRight"); }
And so far the results are much ameliorate, $$anonymous$$ario now lands and walks/runs, the problem at present is that he will only play the leap animation on the way up, non on the mode up and the way down like he is supposed to.
Any idea's?
The reason for that is you are checking to encounter if the velocity of $$anonymous$$ario is positive, or moving up.
Yous should be able to become abroad with just checking to run across if $$anonymous$$ario is on the basis and his moveDirection value.
Also, having else statements later the above statements are redundant. I looked at your code once again, and what you want to do is separate the inputs from the animations. I've edited my postal service with a better breakdown.
Your reply
Welcome to Unity Answers
The all-time place to enquire and answer questions about development with Unity.
To help users navigate the site we take posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Brand sure to cheque out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, meet the list of changes.
![](https://connect-prd-cdn.unity.com/20220318/p/images/3b8ffb87-3737-4658-89e3-44aea4738572_Unity_Answers_V2_370x194.jpg)
Follow this Question
Related Questions
How to Do Grow Animation Like Mario Unity
Source: https://answers.unity.com/questions/313030/transition-from-jump-to-walk-animation.html
- Get link
- Other Apps
perhaps you could check if the histrion is grounded, then bank check if a 'Modest$$anonymous$$arioJump' animation is playing, if it is non playing or has stopped playing and then play/crossfade the Idle blitheness =]
Thanks for the reply. :)
I have been messing around with what yous said trying to figure out how to make information technology work.
The problem i come across is that $$anonymous$$ario has to exist 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 betwixt the two different times when $$anonymous$$ario is on the basis.
I establish the Play$$anonymous$$ode.StopAll which tin be used in blitheness, merely i could not become it to work.
And i just found animation.Finish() perhaps if i put that with the jump animation and an if(!controller.isGrounded && velocity.y < 0) it volition stop the blitheness so i could utilize the walk animation.
Anyway i buggered it'south iv:10am and i think i volition slumber on it and tackle the problem again when i get upwardly.
Thanks over again for the help and if you or anyone else has any other suggestions please feel free. :)