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 MaximusVulcanus · Feb 11, 2013 at 07:07 PM · animationblenderbone

Can I rotation a bone with a script?

Hey Everyone,

New user here on Unity 4. I have a background with C, Java and Blender3D, so I've been working with programming and development tools of all kinds for some time now. I'm initially quite impressed with Unity and I'm hoping to utilize it to eliminate a metric ton of code (particularly around physics, collision and animation).

What I would like to achieve now is bone control via script. As a test case, I just want to click the mouse and send the head rotating around continuously. I can do this fine when I attach the script to the top Parent GameObject, but if I attach the script to the Head "bone" nothing happens.

Looks like there is a great community here. Hope to hear back soon.

-Jeremiah

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
1
Best Answer

Answer by Loius · Feb 12, 2013 at 06:35 PM

When animating bones by code, there's a couple caveats:

If your animation has no animation data for that bone, you can animate the bone freely and/or combine animations. I know that Blender always exports animation for all bones, whether or not they're animated. It's a simple fix to change this in Blender 2.49 (export_fbx.py), but if you just want to animate by code, then...

If you animate in LateUpdate instead of Update, you'll override any animation transforms (since animation happens between Update and LateUpdate).

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 MaximusVulcanus · Feb 12, 2013 at 07:16 PM 0
Share

Thanks for the tips, I'll have to have a look at the blender fbx exporter (not familiar with the format but it may be worth the research).

I'm not sure about the override... what I'm seeing is that the animation reads the data from the bone, sets it in Update, and then in LateUpdate I'm having to compensate for the fact that the position was reset during Update, i.e. rather than just transform.Rotate(1,0,0) I have to rotateValue += 1.0; transform.Rotate(rotateValue, 0, 0);

avatar image Loius · Feb 13, 2013 at 06:08 AM 1
Share

It's better to use absolute rotations (rather than incremental) if you're using overrides (and I'd say it's almost always the right choice, regardless) - something like "head.rotation = Quaternion.LookRotation( target.position - transform.position)"

If you're storing a rotation for, say, using the mouse to aim a bone, it's easiest to store a float value or two ("var rotY : float = 0") and alter those according to your input ("rotY += mouseDeltaX"), then derive a rotation from that ("head.localRotation = Quaternion.Euler(0, rotY, 0)")

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

12 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

Related Questions

Bone rotating entire mesh in Blender, but not in Unity 0 Answers

Meshes not deforming properly when imported from blender 1 Answer

Blender animation problem with armature 1 Answer

Problem with ragdolls and my armatures 3 Answers

Animation not importing right. Blender -> Unity 4 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