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
0
Question by Zuminez · Mar 16, 2021 at 10:40 PM · orientation

I rotated an object around another object's y axis. How do I find the object's degrees in rotation based on that same axis?

I rotated object A around B's Y axis using Transform.Rotate(). Sadly, I know of no way to get the degrees of y rotation for this after the fact. There is a way to get the local rotation and a global rotation, but I know of no way to get A's degrees of rotation around B's y axis. Any of you know how to do this?

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 andrew-lukasik · Mar 17, 2021 at 12:23 AM

From what I can understand you probably asked for this:

  // A's degrees of rotation around B's y axis:
  float degrees = Vector3.Angle( Vector3.ProjectOnPlane(A.forward,B.up).normalized , B.forward );

Tester gizmo:

 [SerializeField] Transform A = null;
 [SerializeField] Transform B = null;
 void OnDrawGizmos ()
 {
     Gizmos.color = Color.yellow; Gizmos.DrawRay( A.position , A.forward ); Gizmos.DrawRay( B.position , B.forward );
 
     Gizmos.color = Color.green; Gizmos.DrawRay( B.position , B.up );
     UnityEditor.Handles.color = Color.green;
     UnityEditor.Handles.CircleHandleCap( 0 , B.position , Quaternion.LookRotation(B.up,B.forward) , 1f , EventType.Repaint );
 
     // A's degrees of rotation around B's y axis:
     Vector3 A_forward_projected = Vector3.ProjectOnPlane( A.forward , B.up );
     float degrees = Vector3.Angle( A_forward_projected.normalized , B.forward );
 
     Gizmos.color = Color.green; Gizmos.DrawRay( B.position , A_forward_projected.normalized );
     Gizmos.color = Color.red; Gizmos.DrawRay( B.position , A_forward_projected );
     UnityEditor.Handles.Label( transform.position , $"angle: {degrees}" );
 }

preview

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
0

Answer by Zuminez · Mar 17, 2021 at 12:12 AM

Transform.Rotate(Vector3 axisToRotateAround, float degreesOfRotation, Space Space.Self);

Eventually it dawned on me that I could just make a global variable....

float yRotation;

And add to it whatever I put in as the degreesOfRotation...

yRotation += angleToTurn * directionToTurn * turnSpeed * Time.deltaTime; A.transform.Rotate(b.transform.up, angleToTurn * directionToTurn * turnSpeed * Time.deltaTime, Space.World);

And I no longer need a Unity function that will give that to me. I am still curious as to how it's done though.

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

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

113 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set the video-playback orientation (iPhoneUtils.PlayMovie) 2 Answers

Difficulties with "Moving the Space, Not the Player" 0 Answers

Smoothing orientation to surface normal rotation 0 Answers

Android camera change based on orientation. 1 Answer

How to set my 3d object orientation with mobile ? 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