Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Cyclops · Feb 14, 2010 at 01:18 AM · rotationtransformmodelbone

How do you rotate a Bone towards a given target?

Given that I have a an imported Blender model, consisting of a cylinder Mesh, and two connected Bones, each half the Mesh length (and vertices weighted accordingly):

How do I rotate the end Bone towards a selected target's position, such that the associated Mesh points towards the target?

When I first created the model in Blender, they were all aligned on the Z-axis, with no rotation. When I saved them to a .fbx file, I specified no rotation on any axis. For whatever reason, the children GameObjects all have a different orientation than the top-level GO.

After importing, my Hierarchy looks like this:

oneTube (GameObject: standard rotation, x=0, y=0, z=0)
- - armature (GameObject: rotation of x=0, y=180, z=0)
- - - - oneBone (GameObject: rotation of x=90, y=90, z=0)
- - - - - - twoBone (GameObject: rotation of x=0, y=180, z=180)

Things I have tried, and couldn't get to work:

The LookAt() function:

twoBone.transform.LookAt(tmpTarget.transform.position);

The LookAt() function on the target in the Bone's Local Coordinate Space:

Vector3 invPos = twoBone.InverseTransformDirection(tmpTarget.transform.position);
twoBone.transform.LookAt(invPos);

Assuming that the Bone object was facing along its Forward vector, and rotating from there:

Vector3 invPos = twoBone.InverseTransformDirection(tmpTarget.transform.position);
Vector3 newDir = invPos - twoBone.position;
Quaternion newRot = Quaternion.FromToRotation(twoBone.forward, newDir);
twoBone.rotation = newRot;

I also tried all three axis vectors up/right/forward, none of which worked. And I tried using the Normal to all three axis vectors, again no joy.

Which brings up another question - what direction is the Bone considered to be facing? How can I determine that from its Transform?

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
2

Answer by jashan · Feb 14, 2010 at 10:46 AM

While not a direct answer to your question, I can recommend some resources that should help nevertheless:

  • Character Animation Tips & Tricks (video from the Unity 2009 session)
  • 3rd Person Shooter (example project: This project shows a range of character animation techniques and tips & tricks.)
  • Head Look Controller (Unity extension: Make characters dynamically turn their heads to look at any point in space)

What I'd try to do is use your model and try to make it work with the Head Look Controller. That way, you should be able to find out whether it's a problem with the setup of your model, or a problem with your scripting. And if it's a problem with your scripting, you can find out how it's done correctly in the source code of the Head Look Controller.

Comment
Add comment · 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
1

Answer by nantas · Oct 11, 2010 at 09:27 AM

Ignore the bone rotation displayed in unity inspector. You need to change the bone rotation in blender to make sure it fits unity's coordinate system.

In blender, turn on "axes" in armature panel so you can see each bone's axis. In blender, z axis is "Forward", -x is "Up". Move around your bone root and tip to get the bone toward correct direction.

If for some reason you can't rotate bone freely (for example the bone is connecting a parent and a child), add a helper bone parenting the bone you want to control with minimal length, and make sure this helper bone's Forward and Up is in correct direction. Then you can control this helper bone via script in unity.

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 Ronin6 · Jan 19, 2013 at 04:29 PM 0
Share

Your answer helped a lot. Z axis for bones in blender will point in the forward direction in Unity. Great for rotating a bone with Transform.LookAt()

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make a bone rotate facing towards a given Transform? 0 Answers

Bone Not Rotating? 1 Answer

Realign transform/model 1 Answer

Attaching a Model to a prefab at runtime 0 Answers

Imported model gives error: "Transform.rotation is no longer valid" 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