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 Mega_Jimmy · Feb 29, 2016 at 07:45 PM · 2d2d-platformer2d animation

2D Animation Controller woes

Hi everyone

I'm trying to make my very first 2D platformer, but I've run into a few problems with the animation aspects.. I have the Animator set up with a trio of animations which run in a loop; Idle --> Jump --> Fall --> Idle. I've checked the Parameters in Play mode and they work a treat. I've got my Animator declared as a Public Animator variable and plugged in the correct Animator on the Inspector. I've also declared Animator, called Anim, with the GetComponent<> function and declared the Parameter-Variables' values in Start.

To be clear, I have a VerticalMovement float and an onGround boolean. The player starts on the ground so VerticalMovement is 0.0f, and onGround is True. The Parameters for each change are;

  • Idle --> Jump (VerticalMovement Greater then 0.1)

  • Jump --> Fall (onGround = false)

  • Fall --> Idle (onGround = true, VerticalMovement Less then 0.1)

Here's the code for the Jump Input, which is inside an Update;

         if (Input.GetButton ("Fire1") && Time.time > nextjump) {
             nextjump = Time.time + jumprate;
             rb2d.AddForce (new Vector3 (0.0f, jumpHeight, 0.0f) * speed);
             verticalMovement = 1.0f;
             onGround = false;
         }

So to be clear I'm trying to change the parameters for the Animator to change to the relevant animation. Do I need to use the Anim.Play() thing or is that irrelevant? (BTW I tried adding Aim.Play("Jump") whilst writing this underneath onGround = false, which plays Jump, goes straight to Fall and then loops Fall endlessly.)

I appreciate this is long-winded but if anyone can help I would be really appreciative!

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 Mega_Jimmy · Feb 29, 2016 at 07:58 PM 0
Share

I can take screenshots and post more if it makes it easier.

avatar image Mega_Jimmy · Feb 29, 2016 at 09:06 PM 0
Share

One final comment. It feels like my code isn't actually talking to the Animator at all.

It's declared in the PublicClass and the vertical$$anonymous$$ovement float and OnGround boolean are both declared at the same time, and their initial values are set in the Start function. And whilst I'm confident the variables are being changed, it feels like it's not passing any of this info back to the Animator itself...

And I'm talking in circles. Sorry.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Injourn · Feb 29, 2016 at 09:10 PM

I ran into a similar problem. What i did catch if the player was grounded by using a Raycast(2D) and used an if statement that asked if the raycast was colliding with another object directly below it. also For changing states from Jumping(In air) to falling, It may better to use velocity there rather than movment. If you are using a rigidbody, this becomes easy. In short boolean for ground check and float for air state.

Comment
Add comment · Show 1 · 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 Mega_Jimmy · Feb 29, 2016 at 10:34 PM 0
Share

Is it possible to use IF statements to deter$$anonymous$$e if the other.GaneObject is an enemy vs ground?

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

77 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

Related Questions

Animated Tiles with using triggers (animating grass) 0 Answers

2d supporting characters 0 Answers

Can you improve my animation/movement code? *Bugs in details 1 Answer

How can I do an Enemy while He's walking his HEAD always see the Target? 1 Answer

Problem with Jump 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