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 Den · Dec 10, 2010 at 02:38 AM · directionangleeuleranglesvectorrelative

Need to know euler angles of Vector3 direction relative to other Vector3 direction

I tried this but it dont work as I expected(the results in euler had to be the same)...

Quaternion relative_rot = Quaternion.Inverse(transform.rotation) * Quaternion.LookRotation(Vector3.up);

     Vector3 relative_rot_euler = relative_rot.eulerAngles;

     Debug.Log("x,y,z : x1,y1,z1 "
         +transform.rotation.eulerAngles.x+", "
         +transform.rotation.eulerAngles.y+", "
         +transform.rotation.eulerAngles.z+" : "
         +relative_rot_euler.x+", "
         +relative_rot_euler.y+", "
         +relative_rot_euler.z           );

The primary idea is to measure deviation of direction in euler angles from one vector3 to another.

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

· Add your reply
  • Sort: 
avatar image
1

Answer by Jesse Anders · Dec 10, 2010 at 04:19 AM

The problem may be that you're using Vector3.up as the (first) argument to LookRotation(), which is likely to produce an invalid result. The second (optional) argument to LookRotation() is the reference vector, which defaults to Vector3.up. If the input vector and the reference vector are parallel or nearly parallel (as is the case in the above code), the results are likely to be invalid.

I'm a little skeptical regarding the usefulness of expressing a relative rotation in Euler-angle form, but I'll just assume you have a good reason for wanting to do that.

Comment
Add comment · Show 7 · 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 Den · Dec 10, 2010 at 12:49 PM 0
Share

Thanks for the answer, but the problem is not resolved... I use euler angles to add torque to rigidbody for selective axes. This torque have to be dependent on relative angles between two vector directions(in my case oject`s down and another world vector).. And as a test I used other arguments to LookRotation() - Vector3.forward for example.. And angles for 1 or 2 axes were quite the same as transform.rotation.eulerAngles, but not for all 3 axes.

avatar image Jesse Anders · Dec 10, 2010 at 10:15 PM 0
Share

To be honest, I kind of doubt the approach you're taking here is viable. (That said, I don't know enough about the problem you're trying to solve to suggest an alternative.)

avatar image Den · Dec 10, 2010 at 11:53 PM 0
Share

I want to stabilize GO rotation using physics (AddTorque) on x and z axes only with respect to, for example, a normal to terrain or some other vector.. Thats what I`m trying to do =) Now I can stabilize to normal to x-z plane using directl transform.rotation.eulerAngles, but can`t do it for random vector. Will try to experiment more..

avatar image Jesse Anders · Dec 11, 2010 at 02:19 AM 0
Share

It sounds like what you'd want to do here is apply a torque (with appropriate magnitude) that's parallel to the cross product of the game object's local up vector and the vector you want to align with. (Reaching a target orientation using applied torque only can be kind of tricky though - you might be able to find some threads on the topic in the forums.)

avatar image Den · Dec 11, 2010 at 12:13 PM 0
Share

Yes, I use PID controller, but I need a feedback of angle (sub of target and current). Tried to add auler angles of two rotations but still could not achieve proper angles.. (((

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

[2D] Angle to Vector conversion 1 Answer

Relative rotation offset? 2 Answers

Setting rotation angle of a bullet fired towards the mouse 1 Answer

Finding rotation 0 Answers

"normalize" a vector but conserve the "- sign" 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