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
2
Question by Cyber_Defect · Apr 02, 2013 at 06:53 AM · rotationlookateuleranglesquaternions

How do I make transform.Lookat use Vector3.down instead of Vector3.forward?

Hey guys,

This seems like a situation that should have come up before, but for some reason I am unable to find a simple solution...

I have a plane I am using for a wall, I have my bones all weighted and in position, I can manually move them into position...

Now why can't I figure out how to make their y property point away from a Vector3?

say I have 2 bones, called bones[], they are vertical at 0,0 and 0,1. they are 1 unit tall. They contain a weighted mesh between them. I want to be able to make them warp that mesh based on a point at (.5f,-10f,.5f) using the bones' down vector.

I have been reading Quaternions and Eulers for 6 hours now /wrist. help! Here is a code smippet I have been playing with based on some tutorials...

(I am aware I should be looping and that my code is inefficient, it is torn down for debugging)

 Vector3 DUMMYCENTER = new Vector3(.5f,-3f,.5f);
         Vector3[] Q2EAnglers = new Vector3[8];
         Q2EAnglers[0] = Quaternion.LookRotation(DUMMYCENTER - DSWBones[0].position).eulerAngles;
             //Q2EAnglers[0].x = 0;//
             Q2EAnglers[0].y = 0;//
             Q2EAnglers[0].z = 0;//
         Q2EAnglers[1] = Quaternion.LookRotation(DUMMYCENTER - DWWBones[0].position).eulerAngles;
             Q2EAnglers[1].x = 0;//
             Q2EAnglers[1].y = 0;//
             //Q2EAnglers[1].z = 0;//
         Q2EAnglers[2] = Quaternion.LookRotation(DUMMYCENTER - DEWBones[0].position).eulerAngles;
             Q2EAnglers[2].x = 0;
             Q2EAnglers[2].y = 0;
             //Q2EAnglers[2].z = 0;//
         Q2EAnglers[3] = Quaternion.LookRotation(DUMMYCENTER - DNWBones[0].position).eulerAngles;
             Q2EAnglers[3].x = 0;
             Q2EAnglers[3].y = 0;
             //Q2EAnglers[3].z = 0;//
         Q2EAnglers[4] = Quaternion.LookRotation(DUMMYCENTER - DSWBones[1].position).eulerAngles;
             //Q2EAnglers[4].x = 0;//
             Q2EAnglers[4].y = 0;//
             Q2EAnglers[4].z = 0;//
         Q2EAnglers[5] = Quaternion.LookRotation(DUMMYCENTER - DWWBones[1].position).eulerAngles;
             Q2EAnglers[5].x = 0;
             Q2EAnglers[5].y = 0;
             //Q2EAnglers[5].z = 0;//
         Q2EAnglers[6] = Quaternion.LookRotation(DUMMYCENTER - DEWBones[1].position).eulerAngles;
             Q2EAnglers[6].x = 0;
             Q2EAnglers[6].y = 0;
             //Q2EAnglers[6].z = 0;//
         Q2EAnglers[7] = Quaternion.LookRotation(DUMMYCENTER - DNWBones[1].position).eulerAngles;
             Q2EAnglers[7].x = 0;
             //Q2EAnglers[7].y = 0;
             Q2EAnglers[7].z = 0;//
         
         
         DSWBones[0].rotation = Quaternion.Euler(Q2EAnglers[0]);
         DWWBones[0].rotation = Quaternion.Euler(Q2EAnglers[1]);
         DEWBones[0].rotation = Quaternion.Euler(Q2EAnglers[2]);
         DNWBones[0].rotation = Quaternion.Euler(Q2EAnglers[3]);
         DSWBones[1].rotation = Quaternion.Euler(Q2EAnglers[4]);
         DWWBones[1].rotation = Quaternion.Euler(Q2EAnglers[5]);
         DEWBones[1].rotation = Quaternion.Euler(Q2EAnglers[6]);
         DNWBones[1].rotation = Quaternion.Euler(Q2EAnglers[7]);
Comment
Add comment · Show 2
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 Cyber_Defect · Apr 02, 2013 at 06:54 AM 0
Share

$$anonymous$$aybe there is a way to extend Transform? $$anonymous$$aybe overload the Lookat() $$anonymous$$ethod?

avatar image Cyber_Defect · Apr 02, 2013 at 10:07 AM 0
Share

cmon, there has to be a solution for this...

1 Reply

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

Answer by whydoidoit · Apr 02, 2013 at 10:14 AM

Create a standard rotation that moves those vectors in general and then multiply the LookRotation by that:

 var rotForwardToDown = Quaternion.FromToRotation(Vector3.forward, - Vector3.up);

  var rotation = (Quaternion.LookRotation(DUMMYCENTER - DEWBones[1].position) * rotForwardToDown).eulerAngles;
Comment
Add comment · Show 5 · 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 Cyber_Defect · Apr 02, 2013 at 10:46 AM 0
Share

Fantastic!

Someone needs to hunt down the creator of Quaternions and dumb him down a bit... preferably with a frying pan.

I was reading your tutorial over at http://unitygems.com/quaternions-rotations-part-1-c/ about this... but when I tried it I had issues.

I need to figure out how to Clamp quaternions now and I think I will be golden, getting some weird rotations now.

Thanks again WhydoIdoit, huge help!

avatar image whydoidoit · Apr 02, 2013 at 11:52 AM 0
Share

I answer a question here http://answers.unity3d.com/questions/420881/limiting-rotation-of-object-specifically-using-scr.html with a function to clamp angles

avatar image whydoidoit · Apr 02, 2013 at 12:03 PM 0
Share

Yeah Quaternions are definitely $$anonymous$$d bending. You have to really forget about eulerAngles and think about what you would want to do with a vector... Where do you want it to point.

avatar image Cyber_Defect · Apr 03, 2013 at 12:59 AM 0
Share

Ok, so I'm sure you remember the Spherized cube question I asked a while back. I pass quads on that sphere to a method and Instantiate a floor/walls on the grid, and they are all facing outward now, however their local rotations on the x/y axis need to remain uneffected by this solution. The localrotation property of the transform is a quaternion though, so I can't just apply a Vector3 to it...

Or maybe I can apply that method above for combining quaternions... hrm

avatar image Andy-Block · Aug 27, 2014 at 10:18 PM 0
Share

BTW, @Cyber_Defect ... the creator of quaternions (http://en.wikipedia.org/wiki/William_Rowan_Hamilton) was dumbed down in a most final way in 1865. I don't believe any frying pans were involved.

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

11 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

Related Questions

Trouble Spawning Bullets with proper rotation 0 Answers

Gyro Sensor based on Euler angles? 0 Answers

LookAt on only 1 axis for 2D games? 1 Answer

Rotating child object around X and Z from different angles causing issues 2 Answers

Object deforms with rotation 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