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 Clonkex · Apr 30, 2014 at 03:24 PM · rotationtransformvector

Calculate differential Euler angles from two Transform.Forward/Up/Right?

I have been having a really bad time trying to find a way to torque a rigidbody around to a target rotation based on its current rotation; the Euler angles are flipping randomly because they're being extracted from a quat.

Anyway, it occurred to me that I may be able to find the difference in rotation between the two objects (the rigidbody and the target bone) using the directional vectors stored in Transform. In my mind this should be theoretically possible.

What I want to do, specifically, is take the Transform.Forward/Up/Right vectors of one object and compare the angles between the points to the Transform.Forward/Up/Right vectors of the other object.

I'm not sure how this would be achieved, but I'm sure it must be possible. I'm no maths guru by any standard, ha, and I'm struggling to visualise how it would work. If it turns out this is not possible for some reason...well, I may just have to cry a little as this may be my last hope for being able to complete my game in Unity... :'(

Any help would be much appreciated, and if my question is worded badly or missing information, please don't hesitate to tell me :)

One last thing: I can't use Quaternions during any stage of this process, because if I do, I have no way of getting Euler angles out again without them being mucked up.

ADDITIONAL INFORMATION

Ok, so I've worked out how it would work (for all of the following, assume 0,0,0 is the origin of the angles):
- To calculate the rotation of the X axis, you calculate the angle between either the Y and Z values of T1.Forward or those of T1.Up, and the Y and Z values of T2.Forward or T2.Up.
- To calculate the rotation of the Y axis, you calculate the angle between either the X and Z values of T1.Forward or those of T1.Right, and the X and Z values of T2.Forward or T2.Right.
- To calculate the rotation of the Z axis, you calculate the angle between either the X and Y values of T1.Up or those of T1.Right, and the Y and X values of T2.Up or T2.Right.

I THINK those are correct, but I really don't know, and it just occurred to me that I don't know what would happen if any of those coordinates ended up 0,0... Now the only thing I need to know (aside from what to do about the coords being 0,0) is how to actually calculate angles between to points with 0,0,0 as the origin.

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 Clonkex · Jun 15, 2014 at 01:13 AM

After all this time, some awesome guy from Stack Overflow solved the very base problem for me :D I posted an answer, because he worked it out entirely in the comments:

http://stackoverflow.com/a/24225689/2288578

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
1

Answer by robertbu · Apr 30, 2014 at 04:38 PM

This might help you. The code is only lightly tested, but for a question about a HUD for play, I wrote some code to get Heading (yaw), pitch, and roll. You might get what you want by calculating these values for both directions and then subtracting them. I don't have time today to test/work out if these values would work for angularVelocity.

http://answers.unity3d.com/questions/696271/how-create-modern-aircrafts-hud.html

Comment
Add comment · Show 3 · 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 Clonkex · Apr 30, 2014 at 11:20 PM 0
Share

@robertbu Actually that sounds like it will be perfect! It gives me the base code to work from, and for any special cases that I find, if any, I can add extra code to handle them. Thankyou very much! If you change your comment to an answer I'll accept it :)

avatar image Clonkex · May 01, 2014 at 04:25 AM 0
Share

@robertbu Question: Why does the heading get calculated with Atan2 and the other two with ProjectPointOnPlane and SignedAngle? Is the heading being calculated as a global angle and the other two as local angles or something? I only need to calculate global angles, so can you give me some tips to get started?

avatar image robertbu · May 01, 2014 at 05:31 AM 0
Share

All the angles are world angles. Put this code on a block and play with the rotation in the Inspector. I'm not sure this code will give you want you want, but the angles are world.

I was designing this code for a aircraft. So I picked a point of reference...a horizontal plane. So all the calculations are done with respect to a horizontal plane. So looking down at that aircraft's forward vector, if I eli$$anonymous$$ate the 'y' of the forward vector, I get the heading like the hand of a clock, on the horizontal plane. Using Atan2() I can get an angle relative to Vector3.right. So for a HUD, I have code that can calculate compass settings.

For the other two readings, I'm looking at the angle between forward/right vectors and that same vector projected on that plane. So for those I have to project the point and then get a signed angle. In thinking about it, I did not really need the ProjectPointOnPlane() code. I could simply eli$$anonymous$$ated the 'y' component to project these vectors on a horizontal plane.

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

20 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

Related Questions

Object not rotating when the associated trigger is triggered 1 Answer

transform.right to vector3 1 Answer

Imported model is rotated 90 degrees off of straight, can't use any transforms 1 Answer

How to make Y-Axis face away from a position? 2 Answers

Rotate an object around another object at an angle from the X axis? 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