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 millej23 · Sep 05, 2016 at 02:14 PM · animator controllermechanim animation

Looking for some guidance on mechanim state machines and coding

Hello All,

This is my first post and I hope I have done it in the correct way!

I have been working on my first "game". Really its just a simple shooter, but mostly a means to help me learn and I have been trying to involve many aspects of unity for learning. I'm looking for some guidance on my player controller and how I have it setup and if I am..well..going down the correct path for animating and moving him. I know there are several ways to execute a task, and I have been going through a ton of tutorials.

I have him moving around the level, no problems there, just simple transform.Translate code.

My character is a simple flying mech that was made in Maya with animations of: Forward, back, left,right, front left, front right(etc) that give the effect of moving in that direction. What I am trying to do is smoothly transition between them using mechanim, when the player moves from left, to right, forward, etc....and then calling those code using the boolean parameters in a script.

What I have is as web of the 8 states in mechanim:

alt text

What I then have from code is something like this:

 if(Input.GetKey(KeyCode.W))
         {
             animator.SetBool("move_forward",true);
                     
         }
         else 
         {
             animator.SetBool("move_forward",false);
             
         }

For moving diagonal my code is:

 if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A))
         {
             animator.SetBool("move_forward",false);
             animator.SetBool("move_LF",true);
         }
         else
         {
             animator.SetBool("move_LF",false);
         }

I know you can use the integer parameters and use the input axis in code, though I am not sure i want this as i already have the movement established elsewhere in code. I am also using DOTween code to create a strafe effect when the player pushes space bar and pointed in the player direction. Here is the code for that, if it is helpful:

 if(Time.time > nextFire && Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.Space))
         { 
         
             Debug.Log("Player Pushing W and A");
             Debug.Log("Spacebar pushed, strafing FORWARD/ANGLE A");
             
                 Quaternion moveAng = Quaternion.Euler(0,-45,0);
                 destination = transform.position + moveAng *(Vector3.forward * strafeAngleSpeed);
                 
                 transform.DOMove(destination,.2f).SetUpdate(true);
                 nextFire = coolDownPeriod + Time.time;

While this system is "working" and I still have to finish some transitions from states, I suppose what I am looking for is some guidance. Am I going down the correct path here? Do the mechanim states look like I am doing things correct for my situation, or should I be doing something more efficient? Am I correctly coding the transitions with booleans or can someone point me in a better direction? I have been seeing some issues when the player pushes both W & A, or S &D(or any 2 keys). It seems to trigger 9/10 times, and sometimes the state will automatically go to "move_forward", instead of move_RF or move_LF. I was able to correct some of this using the interruption source moving from idle to a diagonal direction.

This is my first real project after doing a lot of tutorial projects, and kind of my first intro into bringing my own rigged and animated character into Maya(which is very cool to do, but still very new at it :) ); so any kind of guidance is much appreciated. Thanks!

mechanim.jpg (123.5 kB)
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make character animate as he's rotating? 2 Answers

Animator solution for combining full body and masked animations. 0 Answers

How to add a Animator Controller to a character at runtime? 0 Answers

Move character in a destination with OnClick button 0 Answers

How to make my custom 3rd person character jump? 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