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 CEIJake · Jul 24, 2014 at 03:46 PM · animationmecanim

In place animations using Mecanim and how to script it

Hi, I am a 3D guy so programming can be a little overwhelming at times. So I have a character that I am trying to use in a sidescroller. I have my animations for run, walk, and jump imported into Unity. The way I understand Mecanim is that the animations need to move in the 3d software for them to actually move in Unity as opposed to doing in place animations (which I am currently using). I have been searching all over the place and haven't found any good info on how to use in place animations with the benefits of the Mecanim states and blending and how to script this. If anyone has any resources or suggestions, it would be much appreciated before my wall gets a hole from beating my head against it. Thank!

Comment
Add comment · Show 1
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 Josh Naylor ♦♦ · Jul 24, 2014 at 03:47 PM 0
Share

The Unity website has some great tutorials - http://unity3d.com/unity/animation

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by 0tacun · Jul 24, 2014 at 04:32 PM

You can easily use Mecanim for in-place movement.

I assume you already have a movement script which lets your character move through the level.

What you need is to expand your movement script with the following (in JS):

 //1. we need access to the animator component which is responsible for mecanim, so declare as a variable:
 private var myAnimator : Animator;
 
 //2. we need to let myAnimator know whom animator component we should use, so in Start():
 function Start(){
  //...
  myAnimator = transform.GetComponent("Animator");
  //...
 }
 
 //3. Now we can access the mecanim variables for example in Update() according how we move:
 
 function Update() {
  //move player with rigidbody.addforce or however you do
  
  //now check in which state the player is and change the mecanim variable:
  //for example if our rigidbody has velocity play walk animation:
  if( rigidbody.velocity.sqrMagniture != 0 )
   myAnimator.SetBool("isWalking", true);
  else
   myAnimator.SetBool("isWalking", false);
 
 }

And don't forget to properly set up the mecanim states: alt text


mecanimsetup.jpg (99.1 kB)
Comment
Add comment · Show 7 · 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 CEIJake · Jul 24, 2014 at 04:40 PM 0
Share

Otacun, thanks! That is the direction that I am looking to go with it. I understand what is happening here. I am missing the movement script at the moment. I have a couple I have been messing with but have not successfully figured out how to get the player moving around while playing the animations through $$anonymous$$ecanim.

avatar image 0tacun · Jul 24, 2014 at 04:51 PM 0
Share

Good luck then! You can do it, try to implement my framework I provided into your movement scripts.

If my answer was sufficient, please click "accept answer" :)

avatar image CEIJake · Jul 24, 2014 at 05:27 PM 0
Share

I think that gives a good place to start. Would you happen to have any reference on the movement and force to rigid body? If not, again I have an idea where to start now.

avatar image 0tacun · Jul 24, 2014 at 07:35 PM 0
Share

http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html

The documentation is your deadliest weapon.

avatar image CEIJake · Jul 24, 2014 at 07:40 PM 1
Share

Ah, thanks very much!

Show more comments
avatar image
0

Answer by Xtro · Jul 24, 2014 at 03:54 PM

As a developer, I must say that, if you are a 3d guy, you should find a developer. I don't try to make 3d models since I'm a developer.

Don't get me wrong. Learning new stuff(including programming) is good for a person. The problem is, if you are into programming, you can't start it with complex stuff like game, animation, unity or mecanim scripting. You should begin with the very basics outside of Unity.

https://www.google.com/search?num=50&safe=off&rlz=1C1CHFX_enUS596US596&q=c%23+for+beginners&spell=1&sa=X&ei=EizRU4iaF4TgoAThlYG4CA&ved=0CBsQvwUoAA&biw=1920&bih=1077

Comment
Add comment · Show 4 · 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 CEIJake · Jul 24, 2014 at 04:06 PM 0
Share

I'm not a beginner at program$$anonymous$$g in Unity. I have been doing C# for the past couple years on various projects. Just some of the more complex calls and referencing systems daunt me a little bit. I do 3D, GUI program$$anonymous$$g, animation program$$anonymous$$g, light baking, yada yada on a daily basis. But generally I am able to find reference on things I am not entirely sure about.

avatar image CEIJake · Jul 24, 2014 at 04:19 PM 0
Share

Actually should probably specify that the work I do in script is generally a lot of animation calls a GUI button presses so not a lot of character controlling.

avatar image Xtro · Jul 24, 2014 at 04:35 PM 0
Share

I'm sorry if I offended you. I wrote it because you said "I am a 3D guy so program$$anonymous$$g can be a little overwhel$$anonymous$$g at times."

avatar image CEIJake · Jul 24, 2014 at 05:36 PM 0
Share

No, not at all. I should have specified. I am primarily function as a 3D artist but do some program$$anonymous$$g also but sometimes I have trouble wrapping my head around different things so I go through a lot of reference and a lot of tutorials as well as consult with programmers on methods.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Possible to play single clips using Mecanim? 0 Answers

For easy simple games, you can do without using Mecanim and instead just do it through Scripts? 1 Answer

Mecanim scripting interface 1 Answer

Is it possible to manipulate Mecanim state machine / blend trees from scripting? 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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