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 /
This question was closed May 25, 2013 at 08:36 PM by Fattie for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by baconstrip · May 25, 2013 at 09:13 AM · rotationaxisfacing

How do i rotate something on a new rotation axis?

It's hard to be specific but il try to explain my problem via picture alt text

So i want to rotate the cylinder 45 degrees on the axis that its facing the ball object. (I don't want to rotate the cylinder to face the object and then rotate it 45 degrees) Axis is presented in magenta.

problemo.png (25.3 kB)
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

  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · May 25, 2013 at 06:03 PM

You get the axis using the cross product (Vector3.Cross()) between the Up Vector and the vector to the ball. So the code would be something like this (untested):

 var v3 = ball.transform.position - transform.position;
 var v3Axis = Vector3.Cross(v3, transform.up);
 transform.RotateAround(transform.position, v3Axis, 45.0);

Note this assumes the script is attached to the cylinder. Also you may have to reverse the parameters in the Vector3.Cross() to get the rotation to go the correct direction.

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 robertbu · May 25, 2013 at 06:15 PM 0
Share

Oh, this will fail if v3 and transform.up are the same. This is the situation where the ball is directly above or below the cylinder, so there is no "side" to identify. Since I don't know what you are doing, I cannot advise you on how to handle this case.

avatar image baconstrip · May 25, 2013 at 08:08 PM 0
Share

i think i got it with normalized direction vector and that vector3 cross function, yet i cannot possibly handle that rotateAround function since it behaves uncontrollable if the ball position changes. i used a few quaternion functions ins$$anonymous$$d. thanks!

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Problem changing rotation of 3rd Person Controller 1 Answer

Control object yaw by two axis 1 Answer

how can i substract one axis by 180? 2 Answers

Rolling a capsule lengthways, sideways and twisting with AddTorque 1 Answer

EulerAngles conversion Quaternion problem 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