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
0
Question by anwserman · Jul 23, 2012 at 01:33 AM · animationcharactercontroller

Creating my own character animation controller

So I'm trying to learn more with unity, and I would like to be able to animate my character. On one PC, I downloaded the Penelope tutorial to see how they did animations - and it looks like a mess:

 The Update function is going to contain a lot of conditional checks to determine which animation
 to play. Before we start writing them, we need to get some information about Penelope’s
 horizontal and vertical movement.

Uh, this seems like a disaster waiting to happen - if my character controller already contains this logic (e.g., jumping, etc.) why should I have to duplicate it?

My thought is this. I have my Character Controller, and I create a public variable named "characterState". I could set this variable to "IDLE" or "RUNNING" or whatever, it just needs to store what the character is currently doing. I could then write a seperate Animation Controller that stores a local private copy of this status, and constantly looks to see what the CharacterControllers "characterState" variable is doing. If the local vs. public variable is different, update it locally and play a new animation.

Here's some pseudocode to explain my idea

 CharacterController
 {
       public myCharacterState as ENUM_CHAR_STATE { Idle, Run, Walk }

       Update()
        {

        myCharacterState = IDLE

        if (INPUT = FORWARD)
            myCharacterState = WALK

        }
 }

 AnimationController
 {
       private localCharacterState as ENUM_CHAR_STATE { Idle, Run, Walk }

       Update()
        {
            if (localCharacterState != CharacterController.myCharacterState)
            {

                if (CharacterController.myCharacterState == IDLE)
                    playAnimation(IDLE)

                if (CharacterController.myCharacterState == WALK)
                    playAnimation(WALK)

                if (CharacterController.myCharacterState == RUN)
                {
                   if (localCharacterState == WALK) 
                   {
                       // blend animation
                   } else { 
                      // replace animation
                   }
                }
                
                //etc....


                localCharacterState = CharacterController.myCharacterState
            }
        }

 }





This is just some rough pseudo-code I just threw together to get my point across. However, since Unity is all new to me, what are the disadvantages that I could experience by programming it in this fashion?

EDIT: I just thought of something, what if the player is RUNNING and JUMPING? Or FALLING and HIT WITH A ROCKET? I would argue that the most recently applied animation should be the one that plays on through - the animation shouldn't determine gameplay. And in the case of FALLING and HIT WITH A ROCKET, if getting injured while falling cancels gravity and let's you float in the air, that's just poor programming to begin with ;)

Comment
Add comment · Show 5
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 · Jul 23, 2012 at 02:08 AM 1
Share

You should check out the 3D Buzz tutorial, it covers having an animator class : http://www.3dbuzz.com/vbforum/content.php?212

scroll down to : Section 3 - Enhanced Character and Camera Control : 7 - TP_Animator Overview and Theory

They use 4 classes : Camera, Controller, $$anonymous$$otor, Animator

http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Camera.cs

http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Controller.cs

http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_$$anonymous$$otor.cs

http://www.alucardj.net16.net/unityanswers/TPC_Tutorial/TP_Animator.cs

avatar image anwserman · Jul 23, 2012 at 06:38 AM 0
Share

So - basically, it's exactly what I stated except that they split the input and character controls into their own separate classes - which is a smart thing to do (I'm currently working off of the base scripts so just starting off). EDIT: Noticed that they moved the actual movement code into the animator class (which I dislike)

avatar image AlucardJay · Jul 23, 2012 at 07:23 AM 0
Share

yep, I upped the scripts hoping they would be a useful reference. Agreed all the movement should be in the $$anonymous$$otor script. Hopefully an experienced programmer can give more info on what are the disadvantages that I could experience by program$$anonymous$$g it in this fashion.

avatar image anwserman · Jul 23, 2012 at 07:27 AM 0
Share

Ok, well this is a good reference. I'm glad you agree too - I'm a fan of decoupling (though my code sometimes doesn't reflect it!) Ideally, the code should be a one-way weak relationship. If I have my input class, it should still work even if I remove the $$anonymous$$otor class. Same for Animator class, if I remove it the $$anonymous$$otor class should still work. Now, if I remove the input class, I would be dumb to assume that any class that relies on it to continue working.

avatar image wmichaelv · Mar 06, 2014 at 09:27 PM 0
Share

links are dead. Requesting re-upload.

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

6 People are following this question.

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

Related Questions

Third Person Controller 1 Answer

Climbing stairs and climbing on a slide 0 Answers

Player Animation and control panel 2 Answers

Character controller movement 1 Answer

independent arm from body - unity2d 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