• 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 Cherno · Dec 08, 2013 at 05:38 AM · animationrotationbonepivottransform.lookat

Help: Making an object face a target

My character model's upper body should be turned towards a target. Problem is, the bone that controls the torso has a pivot as seen on picture 1.

 TorsoBone.transform.rotation = Quaternion.LookRotation(Target.transform.position - TorsoBone.transform.position, Vector3.up)

Using Vector3.up as the "up vector" as specified on Quaternion.LookRotation produces the rotation as seen on picture two.

I have tried all possible Vectors, both World Vectors (Vector3s) and local ( TorsoBone.transform.*), it either didn't change anything or produced further weird rotations.

How can I make the bone with this pivot turn towards the target? :) (In all cases, the target is where the feet are pointing at) EDIT: In both pictures, the selected object is NOT the human model (which has a correct pivot), but the "torso bone" with it's faulty pivot (which can't be changed so it has to be done via script).

Picture 1 Picture 2

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 Cherno · Dec 08, 2013 at 11:58 PM

I finally got it working with an acceptable workaround:

I use a seperate empty gameobject as a torso controller but only temporarily insert it into the hierarchy as a parent to the actual torsoo bone, just AFTER making the model assume the firing stance/pose, and then after the shooting is done I parent the torsobone back to it's normal parent bone (pelvis in this case).

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 Tomer-Barkan · Dec 08, 2013 at 06:18 AM

It can be seen from your screenshot that the model you are using is facing upwards, and not forward (the blue arrow is forward, the green line is upwards).

This means that if you set your model to face a location, its left side (the blue line) will face that location.

I very strongly recommend that you fix the model so that it's facing forward (positive Z axis), because you will have a lot of issues in your game if you use it like this.

If that is not possible for some reason, I recommend making a parent empty game object to your player, and rotate the player manually so that it is facing the empty object's forward axis (positive Z again) - it should be 90 or 270 rotation on the X axis, according to the screenshots. Once you do that, apply all rotations and movements to the parent object. Make no changes whatsoever to the child transform. The parent object can be considered as your player from now on, since it is facing correctly.

Comment
Add comment · Show 6 · 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 Cherno · Dec 08, 2013 at 02:09 PM 0
Share

Sorry I didn't state it, the selected object in both pictures is not the human model itself but the "torso bone". The human model has the pivot set up correctly, but the torso bone doesn't. It's not possible to change bone pivots in 3D Studio $$anonymous$$ax so this has to be somehow done by script :(

avatar image Tomer-Barkan · Dec 08, 2013 at 02:24 PM 0
Share

Then go for the parent object solution I described in my answer. Put your character inside a gameobject and rotate it so that it faces the parent's forward vector. Then make any transform changes (rotations and movements) on the parent object ins$$anonymous$$d.

The only other option would be to do all your calculations, so that ins$$anonymous$$d of facing the target, you will face 90 degrees to the right of the target. It is possible, but you can expect to have lots of issues during the work on this game.

avatar image Cherno · Dec 08, 2013 at 02:44 PM 0
Share

$$anonymous$$aking a parent object for the whole character wouldn't do anything since the character model pivot is already correct. I already tried putting an empty gameobject into the bone hierarchy between the torso bone and it's parent, and it actually works, but then the animation doesn't work anymore because the hierarchy has changed (I presume).

I'm surprised there seems to be no simple solution to this since it has to be a common problem for everyone who uses bones/bipeds and wants to, for example, make the upper body face a target during shooting.

avatar image Tomer-Barkan · Dec 08, 2013 at 02:55 PM 0
Share

I'm not big on 3ds, but I'm surprised you're not able to change the orientation of the model so that it faces forward, and then re-import...

Ok, here's a solution to your specific problem, but I expect you to encounter other issues in the future using this model...:

Ins$$anonymous$$d of:

 TorsoBone.transform.rotation = Quaternion.LookRotation(Target.transform.position - TorsoBone.transform.position, Vector3.up)

Use:

 TorsoBone.transform.right = TorsoBone.transform.position - Target.transform.position;
avatar image Cherno · Dec 08, 2013 at 03:04 PM 0
Share

I am indeed able to change the model's orientation (although I don't have to since it's already correct), but what I can't do is change the bone's rotation.

Anyway thanks for your help, for now I'll go with just rotating the whole model towards the target with is not as satisfying but has to suffice. $$anonymous$$aybe once I get a full license I can make it work via inverse kinematics.

Show more comments

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

Animation rotation problem. 0 Answers

How do you change the pivot point of a group? 1 Answer

Rotate a child bone during animation? 1 Answer

How to rotate a bone during an animation? 2 Answers

Animation interfears Player-Movement 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