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 28, 2014 at 03:08 AM · rotationquaternioneulerangleseuler

Is there no way to get reliable angles from a rigidbody?

I need to get the current angles of a rigidbody so I can apply countertorque to keep it at a particular orientation. Is there really no way to get reliable Euler angles from the rigidbody? Unlike most of the rest of my game, I can't simply keep the current angles in variable and modify them myself because the physics controls the rigidbody.

If there's no way, then why not? It's unbelievably frustrating that everything is stored as stupid Quaternions, when there's no way to get Euler angles from them.

I can't believe I've put this much effort into Unity for nothing.

EDIT:

I don't mean "how do I get Euler angles from a Quaternion", I mean "how do I get reliable Euler angles from a Quaternion".

Comment
Add comment · Show 4
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 Scribe · Apr 29, 2014 at 09:46 AM 0
Share

what are you reading the rotation from? is it just the rigidbody.rotation or is it some kind of rotational speed? If you are using AddTorque like you mentioned in a comment, it doesn't take a rotation, it takes an axis to rotate around I believe so you may want to use Quaternion.ToAngleAxis or whatever it is.

avatar image Owen-Reynolds · Apr 29, 2014 at 04:47 PM 0
Share

The only time I apply rotational torque is when I think the object may be blocked by something, and need physics to prevent overlap. The math is a pain. Otherwise RotateTowards works fine (in a restricted area, it can force long objects to spin through walls.)

Otherwise I think a lot of people use joints, which compute the torque, etc... for you.Like connecting the front of your object with a spring to an empty always in line with the target.

avatar image robertbu · Apr 30, 2014 at 02:21 PM 0
Share

A few days ago for a question about a HUD display for a plane, I worked out some code for Heading (Yaw), $$anonymous$$ch, and Roll. The code is only lightly tested, and I have not tested it in conjunction with applying angular velocity of a Rigidbody, but it might be helpful for you:

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

avatar image JanusMirith · Aug 11, 2014 at 03:59 AM 0
Share

I totally understand the frustration, there are a lot of solutions for tracking the Euler angles of a object you are modifying, but nothing reliable to go the other-way.

I am dealing with hingeJoints that take a angle as an input and there seems to be no way to get or track the rotation of a transform without horrid issues.

You are not alone :(

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by homer_3 · Apr 28, 2014 at 03:13 AM

https://docs.unity3d.com/Documentation/ScriptReference/Quaternion-eulerAngles.html

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 Clonkex · Apr 28, 2014 at 03:56 AM 0
Share

Why did you post that? The problem is not getting Euler angles from Quaternions, the problem is getting them reliably. I did say that in my question...

avatar image homer_3 · Apr 28, 2014 at 12:32 PM 0
Share

You asked

Is there really no way to get reliable Euler angles from the rigidbody?

And there is, using the API I linked.

avatar image Owen-Reynolds · Apr 28, 2014 at 07:07 PM 1
Share

homer_3: the issue happens when you try to look up and use things like transform.rotation.euler.x and get a "random" result. It's a very common problem here.

To see it, take an unrotated object and tip it forward (around x.) You'll see that after x hits 90, y and z flip to -180 and x starts going back to 0 from 90. Typing in (110,0,0) works, but snaps to (70,-180,-180) if you move a tiny bit. So for that angle, euler.x is 70 or 110, depending.

This is why the docs say not to read or set just one eulerAngle.

avatar image Clonkex · Apr 29, 2014 at 12:59 AM 0
Share

@Owen Reynolds Wait, what? Are you saying the angles are reliable if you extract all three at once using rotation.eulerAngles, or are you saying that while the resultant rotation is identical, the individual parts of the Euler may change randomly?

@homer_3 I apologise for being so rude. I was just frustrated that there was no possible way to actually use the rotations stored in the rigidbody. So...I apologise.

avatar image Owen-Reynolds · Apr 29, 2014 at 04:34 PM 0
Share

Yes and yes. It's like someone who might tell you the time as 10:45, then a $$anonymous$$ute later as "14 to eleven." But, I've never seen anyone extract all three Euler-angles as a whole and do anything useful with them.

avatar image
0

Answer by Owen-Reynolds · Apr 28, 2014 at 05:39 AM

Unity didn't invent Quaternions. It uses them because other game engines do, because they're considered the best way to do 3D angles.

For real, there isn't a 1-1 mapping between Quaternions and the YXZ "Euler" representation. When you pull out a Euler angle, there's no way to know which of the 2(?) possible results you want. You can't get consistent results, because of math.

You can project transform.forward onto planes and compute using trig. Of course, you'll get huge snaps if the object faces the main axis (this is what Quaternions avoid.) Easier is just to do everything in Quaternions. Save the wanted facing as a Quaternion, and figure out how to push from one Quat to another (I use X-product of their "forwards". Oddly, it works as angular velocity numbers.)

Comment
Add comment · Show 4 · 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 29, 2014 at 01:08 AM 0
Share

1st paragraph: I know, I know...I'm sorry, I didn't mean to be so angry in my question, I was just frustrated (which is no excuse). I mean, there's no way to get the Euler angles out of a rigidbody. I just would have thought someone would have come up with a better solution for rotations by now, given they are so important in games. If they insist on using Quats internally (which does make sense, of course; Quats are a great way to represent rotations), then they need to make the rest of their commands Quaternion-compatible. That is, I need to be able to input a Quat into RigidBody.AddTorque() to push physics object around.

2nd paragraph: Yeah...I feel like I should just give up on my project because apparently it's physically impossible to get consistent results from rotation.eulerAngles... I really have no idea what else to do.

3rd paragraph: I have no idea what you just said there... ;)

avatar image Owen-Reynolds · Apr 29, 2014 at 04:39 PM 0
Share

I have the most luck using a combination of Quaternions and "facing vectors." For example, transform.forward is the way you're facing, and target.position - my.position is the way I want to be facing. Then a built-in can give you the angle (Quaternion) between them. But that takes practice and a trig review.

avatar image Clonkex · Apr 30, 2014 at 01:38 PM 0
Share

@Owen Reynolds I have no idea what you actually mean (what's a built-in?), although I've been racking my brain for clever alternate ways of achieving what need, and the idea of using position to find angles independent of stored rotations seems like a good place to start. Besides, your method would create a Quaternion, the very thing I'm trying to avoid, as I need Euler angles to calculate torque to apply to a rigidbody.

avatar image fafase · Apr 30, 2014 at 03:56 PM 0
Share

You can convert quaternion to euler and vice-versa using

 Quaternion.Euler(euler angle in vector3)
 Quaternion.eulerAngles = new Vector3();

Now there is also a correspondance between quaternion and euler, it is no magic, so if you want to work your own: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles but it is waht those two previous methods are doing.

To be honest, I don't really understand your issue, maybe a clear situation would help finding a solution. $$anonymous$$aybe there is a simple way to achieve what you are after but you may be going the wrong direction.

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

24 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

Related Questions

Can't Accurately Read Rotations 0 Answers

trouble with Quaternion rotation in 360 axis degree 0 Answers

Fixing the rotation around a particular axis using Quaternions? 2 Answers

Need help with storing Rotation in a Quaternion 1 Answer

Object makes random jumps in 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