Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Mischa · Oct 07, 2011 at 11:47 PM · rotationquaternionaxisairplane

Quaternion Rotation around Local Axis

What would be the simplest way of rotating an object around his LOCAL axes using 3 Quaternions for each axis as an absolute rotation?

I need this for an airplane rotation. I have the absolute rotations for each axis as:

 Quaternion yaw;
 Quaternion pitch;
 Quaternion roll;

I can't do:

 transform.rotation = yaw * roll * pitch;

Because that would combine the rotations according to worldspace, as discussed here

Would I have to apply the yaw rotation first, then recalculate and apply the roll rotation, then recalculate and apply the pitch rotation? What would be the best way to do this?

Thanks for your thoughts!

Comment
Add comment · Show 1
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 cregox · Oct 25, 2011 at 07:03 PM 0
Share

related: http://answers.unity3d.com/questions/171380/camera-relative-free-orbit.html

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by DaveA · Oct 08, 2011 at 12:34 AM

Why not just use eulerAngles? http://unity3d.com/support/documentation/ScriptReference/Transform-eulerAngles.html for example

Comment
Add comment · Show 1 · 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 Mischa · Oct 08, 2011 at 08:40 AM 1
Share

the problem with eulerAngles is, that I can't define the order in which the rotation is computed. And for some special cases, I should have the plane rolled before applying the pitch..

Would there be any way to do that with eulers?

avatar image
0

Answer by aldonaletto · Oct 08, 2011 at 10:51 AM

The big problem here is: in a real airplane, all rotations that you apply refer to the airplane local axes, but when combining rotations the combination order modify this - the first rotation refers to the world axes (since no rotation was applied yet), the second use the axes rotated by the first rotation, and only the 3rd will be totally local, since the other axes were already rotated (side note: rotations run right to left, so the rightmost quaternion applies the first rotation).
To mimic a real airplane, you should apply the rotations incrementally to the current object rotation - maybe using the old Rotate, like this:

float yawSpeed = 10f; float rollSpeed = 15f; float pitchSpeed = 12f;

void Update(){ float y = Input.GetAxis("Mouse X")*yawSpeed*Time.deltaTime; float r = Input.GetAxis("Horizontal")*rollSpeed*Time.deltaTime; float p = Input.GetAxis("Vertical")*pitchSpeed*Time.deltaTime; transform.Rotate(p, y, r); // Rotate uses Space.Self as default } This works fine when someone is handling the controls, but may fail if used by AI because the accumulation of small errors over time lead to weird results: the angles don't return to zero, or rotation from one axis "leaks" to the others.

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 Mischa · Oct 08, 2011 at 02:30 PM 0
Share

"This works fine when someone is handling the controls, but may fail if used by AI because the accumulation of small errors over time lead to weird results: the angles don't return to zero, or rotation from one axis "leaks" to the others."

Unfortunately that's exactely the case. - I'll have an AI controlling the plane. - I'd like to Lerp the roll rotation to a maximum roll, to get a smooth behaviour.

$$anonymous$$aybe I could do it incrementally and control the rotation speeds by comparing some of the local and world orientation vectors and get the angles between them?

I'm experimenting right now, and I urgently need a wall to bang my head on.. and coffee.. anyway, would be cool if anyone has a suggestion how to achieve those special rotations :)

avatar image aldonaletto · Oct 08, 2011 at 05:50 PM 0
Share

I suppose that pitch and roll are zero most of time, right? If that's true, you can reset them when you know that they should be zero. You can call a reset function like this:

void Reset$$anonymous$$chRoll(){
    transform.rotation = new Vector3(0, transform.eulerAngles.y, 0);
}
Or maybe something more smooth, like this:

IEnumerator Reset$$anonymous$$chRoll(){
    Quaternion newRot = new Vector3(0, transform.eulerAngles.y, 0);
    for (float t = 0f; t < 1f;){
        t += 5*Time.deltaTime;
        transform.rotation = Quaternion.Lerp(transform.rotation, newRot, t);
        yield return 0;
    }
}
Anyway, assigning some well known value to rotation at some interval is the way to correct these cumulative errors.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Finding the Euler angles of an object's rotation in terms of a different set of axes 0 Answers

Lookat via Single Axis 0 Answers

Tank urret rotation - Need help. 1 Answer

Rotating tank barrel on X axis while the parent Turret rotates on Y axis 2 Answers

Duplicating rotation with axis constraints 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