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
1
Question by drizztmainsword · Feb 17, 2013 at 09:06 PM · animatormecanimlookat

Mecanim/Animator SetLookAtPosition not working

I have a character controlled by a Mecanim Animator. I want to be able to precisely position the character's head.

     public Transform lookTransform; // An object set in the editor, not null
     
     // Update is called once per frame
     void Update () {
         if (lookTransform != null) {
             Animator animator = GetComponent<Animator>();
             animator.SetLookAtPosition(lookTransform.position);
             animator.SetLookAtWeight(1.0f);
         }
     }

This results in no effect whatsoever. As far as I can tell, I'm using the same code from the Mecanim example project (the one where the robot shoots lasers at the floating sphere). I'm using Unity Free; is that possibly the reason?

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 Fattie · Sep 30, 2016 at 06:37 PM 0
Share

also a very common gotchya: http://answers.unity3d.com/answers/650502/view.html

3 Replies

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

Answer by drizztmainsword · Feb 18, 2013 at 12:52 AM

I apparently have a nasty habit of answering my own questions.

It would appear by looking at the Unity Store that the head look functionality is limited to the Pro version of Unity. This is the only place I have found any information about it; there is no mention of the feature being Pro only in the scripting documentation. There is also no warning within Unity when attempting to call this Pro-only feature; it merely fails silently.

It looks like I'm going to be building my own.

Comment
Add comment · Show 5 · 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 waschtel · Apr 03, 2013 at 12:02 PM 0
Share

There already exists such a script http://wiki.unity3d.com/index.php?title=HeadLookController . It works great with the old Locomotion-System but I didn't test it with $$anonymous$$ecanim.

avatar image TonyLi · Apr 03, 2013 at 01:21 PM 1
Share

For others browsing this question and using Pro, you should call SetLookAtPosition() and SetLookAtWeight() inside of OnAnimatorI$$anonymous$$(), not in Update().

avatar image drizztmainsword · Apr 03, 2013 at 01:29 PM 0
Share

@ waschtel: Doing it myself has actually been rather beneficial. It has allowed me to have head oriented based on the root or the chest of the character, it has allowed me to control whether or not the chest is included in the I$$anonymous$$ algorithm, and it works directly on mouse/joystick movements ins$$anonymous$$d of by telling the head to look at a point in space.

@TonyLi: I would imagine OnAnimatorI$$anonymous$$() runs at some point around LateUpdate(), which is where you would go to modify any animations. In fact, I never checked using those functions in OnAnimatorI$$anonymous$$(), so maybe they will work there? No matter, I have a version more suited to my needs now.

avatar image Anxox · Nov 21, 2013 at 01:04 AM 0
Share

Thank you for answering this yourself. I thought I was doing something wrong for the past hour. Even re-imported and re-setup the avatar b/c I thought I might have set that part up wrong.

avatar image Randize · Dec 01, 2013 at 12:54 PM 0
Share

Oh nice! Thanks for pointing that out, I have been wondering that for the past few hours too. Unity should really notify that in the console or something.

avatar image
3

Answer by Stardog · May 31, 2015 at 11:35 PM

OnAnimatorIK will only work if it's on the same GameObject as the Animator component.

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 Rodolfo-Rubens · Aug 10, 2015 at 02:58 AM 0
Share

Thanks, that solved my problem.

avatar image
1

Answer by peter.parker · Oct 13, 2014 at 11:59 AM

First, write this in Start() of any script for Pro version

 bool hasPro = UnityEditorInternal.InternalEditorUtility.HasPro();
 print ("Unity Version Pro: " + hasPro);

If it returns true, then reconfirm by running this

 void OnAnimatorIK (int layerIndex) {
    print ("OnAnimatorIK - running");
 }

As, the above code only runs in Pro version.

Remember that OnAnimatorIK is a callback function, so it must be on the object having animator component. Also, remember that in your animator controller, in your animation layers IK Pass should be checked.


Hope, it will save someone's time finding problem on IK.

And look here:

http://answers.unity3d.com/answers/650502/view.html

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 Fattie · Sep 30, 2016 at 06:22 PM 0
Share

great tips!

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

15 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

Related Questions

Mecanim state that keeps last pose? 0 Answers

Switching Animator on/off 0 Answers

Mecanim CrossFade transition interruption issue 3 Answers

Clone character with new character's animator playing at the same transition position 0 Answers

Should I use playables, mecanim, or legacy to create keys and clips ? 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