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
0
Question by fholm · Aug 07, 2011 at 11:17 AM · rotationraycastcoordinates

How to rotate torso (sub mesh) of a model?

I've been trying to get the upper body / torso of a model (the player one from the AngryBots demo) to rotate to wherever the mouse pointer currently is.

The very simple C# code looks like this:

 public Transform UpperBody;
 
 void Start () {
 
 }
 
 void LateUpdate () {
     var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     
     if(Physics.Raycast(ray, out hit, Mathf.Infinity)) {
         var hitPoint = hit.point;
         var rotation = Quaternion.LookRotation(hitPoint - UpperBody.position);
         UpperBody.rotation = rotation;
     }
 }

The public UpperBody field is set to the root bone (the spine in thise case) of the upper body. And while the model does rotate as I move my mouse, it is not correct as he keeps looking straight up in the air and is rotated away from my mouse:

alt text

I've been thinking it probably has something to do with the fact that the origin of the local coordinate system for the spine doesn't have standard up/left/forward angles, like this:

alt text

But even if this is the problem, I have no idea of what I need to do make it rotate correctly.

Comment
Add comment · Show 3
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 fholm · Aug 07, 2011 at 11:34 AM 0
Share

I've also tried doing this UpperBody.LookAt(hit.point, Vector3.left); to have the UpperBody look at the hit.point and adjusting the world up vector to be Vector3.left which is the up vector for the local coordinate system for the torso

avatar image SisterKy · Aug 07, 2011 at 02:43 PM 0
Share

Did you not format your post at all or did UnityAnswers loose the formatting? (it does that sometimes...) anyway, please format. hardly anyone will like to answer to that as is...

avatar image fholm · Aug 07, 2011 at 02:57 PM 0
Share

what the hell, yeah UnityAnswers ate all the formating apparently. jesus.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make 2 object not go into each other when modifying one object's position 0 Answers

Unity Rotate Raycast on Quaternion 1 Answer

Automatically rotating objects to fit on to others 0 Answers

Rotate an object from inside (With Flipped Normals) 3 Answers

How can I smooth the rotation using quaternion and raycast? 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