• 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 Waliactico · Aug 06, 2013 at 05:46 PM · animationmecanimorientation

Mecanim legs orientation

I'm making a 3rd person shooter, and I have 4 animations for moving (forward, strafe both sides and backwards). What I want now, is that in the intermediate directions between, for example, forward and strafe, the legs (actually, the hip) orient towards that direction, keeping the torso looking forward (since it's a shooter). Is there any way that I can do this, by any means? Thank you in advance

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

2 Replies

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

Answer by Waliactico · Aug 07, 2013 at 10:59 AM

For anyone interested, blendtrees didn't work nice, because they need to have intermediate animations too, and I want the character to be always facing the camera forward with its torso. As I don't have these animations, I discarded blend trees, and instead I used a manual rotation of the bones directly. Mecanim updates the transform of the bones during the function OnAnimatorMove(), so we need to update them afterwards. LateUpdate() would be ok to do that. One thing important is that on every frame, Mecanim resets the bones transform, so they don't remember its previuos position. So we need to create a variable which remember what we want, and update it each frame (in an OpenGL style). This is a kind of stupid example that rotates steadily a bone around Y axis, while the animation keeps playing:

 public class BoneManualRotation : MonoBehaviour {
     public Transform boneTransform;
     private float angle=0;
     
     void LateUpdate() {
         boneTransform.Rotate(0,angle,0);
         angle += 5.0f;
     }
 }


So, to meet my goal, I couldn't just rotate the hips, since they are the root transform and rotate the entire model. So what I did was rotate the model itself to the direction the player is facing, and then correct that offset in the inverse direction only with the spine bone, so the torso faces the camera forward. I hope this information would be useful to someone!

Comment
Add comment · Show 2 · 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 Sylker · Nov 20, 2013 at 09:31 AM 0
Share

I was looking for the same thing wondering if there's any $$anonymous$$ecanim built in solution. Your answer worked great and your stupid example was an amazing starting point. I just used

 if (Input.Get$$anonymous$$ouseButton(1))
     boneTransform.rotation = Camera.main.transform.rotation;

and everything worked like a charm. Thanks.

avatar image marckeeling · Dec 05, 2013 at 01:44 AM 0
Share

Is this still the best way to achieve Angry Bots style third person animation (strafe and torso independent ai$$anonymous$$g) in mecanim?

avatar image
0

Answer by Xtro · Aug 06, 2013 at 07:51 PM

Try animation blending in mecanim.

You should watch the locomotion tutorial. Actually it's teaching about walk and turn. not walk and strafe. But you can get an idea how to do it.

This is the official video : http://video.unity3d.com/video/7362044/unity-40-mecanim-animation-tutorial

But there are many videos if you google "unity mecanim locomotion tutorial"

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 Waliactico · Aug 06, 2013 at 07:56 PM 0
Share

I'm sorry, but what exactly is locomotion in mecanim? I've already seen that video, and I don't remember anything like what I want...

avatar image Xtro · Aug 06, 2013 at 08:04 PM 0
Share

in official mecanim tutorial video, locomotion is a animation blending state.

it's blending the walk and turn animations according to a direction parameter.

if the direction is 0, it only plays walk animation. if -1, it plays turn left. if in between, it blends the walk and turn animations.

you can do the same with walk and strafe animations.

avatar image Waliactico · Aug 06, 2013 at 08:06 PM 0
Share

So, I think you mean blend trees, right? I would try that, and see if it works, thanks!

avatar image Xtro · Aug 06, 2013 at 08:08 PM 0
Share

Oh yes. This is the correct name. I just remembered the custom blend tree name in the video.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Mecanim animation issue 1 Answer

Can the mecanim animators Controller var be set in code? 1 Answer

Using Override Animation Controllers (NOT WORKING) 0 Answers

Random float parameter for idle animations 1 Answer

Multiple Animation Events Parameter Mecanim 1 Answer


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