Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Farmerfromtexas · Jul 17, 2019 at 05:28 PM · rotationanimatoranimationcliplateupdateread-only

Combining rotation movement from C# script with rotation movement from animation

Dear unity friends,

The 3D model in my scene has a looping idle animation which among others rotates the eyes. Through C# I also rotate the eyes towards the camera position:


 public GameObject leftEye;
 public GameObject rightEye;
 public GameObject cam;

 private void LateUpdate()
 {
  // Find out where we want to look    
 Quaternion targetRotation = Quaternion.LookRotation(cam.transform.position - leftEye.transform.position);
  targetRotation *= Quaternion.Euler(-90f, 0f, 0f);
  leftEye.transform.rotation = targetRotation;
  rightEye.transform.rotation = targetRotation;
  }

I'd like to add the eye rotation movements from the animation relative to the rotation movement from the script. At the moment the script overrides the animation movement.

The problem in the posts below are kind of similar but I haven't managed to derive a solution to my problem from them or from other sources.

  • https://answers.unity.com/questions/402259/how-to-combine-mecanim-and-script-based-bone-movem.html

  • https://answers.unity.com/questions/126368/how-to-rotate-a-bone-during-an-animation.html

Help is very much appreciated and I wish wonderful things upon you.

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

1 Reply

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

Answer by ishumshark · Jul 17, 2019 at 08:29 PM

To the best of my knowledge, it is impossible to simultaneously control the transforms of objects with an animation and from a script. However, it is possible to split that control between a parent and child.

I'm not sure what your animation is doing to the eyes, but I'm guessing you are using the script to point the eyes in the general direction of the camera, and then control the finer movements with the animation?

If so, I would child each eye object to an empty game object, then use your script above to point that object, with the eye inside, at the camera. Then you can use an animation to control the eye itself, so it would rotate and move relative to the empty parent.

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 Farmerfromtexas · Jul 19, 2019 at 06:22 PM 0
Share

@ishumshark "I'm not sure what your animation is doing to the eyes, but I'm guessing you are using the script to point the eyes in the general direction of the camera, and then control the finer movements with the animation?"

Yes that is exactly what I'm trying to achieve. And your solution of parenting an empty object with the script to the animated eye objects is exactly what I was looking for! Awesome and thanks a lot!!

I did however run into some follow up problems which I'll describe here with the solutions that worked for me, in case other people run into them:


  1. Firstly, when adding a parent game object to the hierarchy of your animated game object it breaks the animation path to all its child objects. In the Animation Window you'll have to re-link the broken animation links, highlighted with yellow text, by clicking twice on the highlighted text (or pressing f2 when it's selected) and rena$$anonymous$$g the animation path accordingly. Rena$$anonymous$$gAnimPath.jpeg See also the following post: https://answers.unity.com/questions/981781/animation-window-yellow-text-after-moving-animatio.html


  2. Secondly, in my case the Animation Clip was embedded inside the .fbx model and was Read Only. ReadOnlyAnimClip.jpeg This means you can assign a new path but it won't save to the model. If you close Unity, the animation paths will be broken again next time you start it up. What worked for me here was to duplicate (Ctrl+D) the Animation Clip inside the model in the assets folder, better described by user "davejas" in the following post: https://forum.unity.com/threads/removing-read-only-from-animation-clips.514549/

In case you're working with the Animator Controller to animate your object like I was, you'll have to reassign the duplicated Animation Clip to the appropriate state. Go to the Animator Window press on the state you wish to assign the animation to and drag the new Animation Clip from your assets folder to $$anonymous$$otion in the inspector.

Thanks again for the help!


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

303 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Run smooth continuous rotation animation of spinner using animator 1 Answer

2D sprite animation issue 0 Answers

Cant find animation target 1 Answer

How to reset animator controller ? 4 Answers

How can I add a motion clip to the animator state by script? 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