Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Xav_m · May 21, 2011 at 03:02 PM · rotationquaternioncombine

how to combine 2 quaternion components?

Hi, I want to combine the rotation components of 2 quaternions, giving as result:

 aQuat.x, bQuat.y, aQuat.z

how can I achieve this?

Thanks.

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 Owen-Reynolds · May 21, 2011 at 04:10 PM 0
Share

I'd say to start with what you want in physical terms. For example, quat#1 is a facing, and quat#2 is a "facing tweak" such as "10degs left and 5degs up from current facing."

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by Peter G · May 21, 2011 at 03:12 PM

I highly doubt that you want to do that.

  1. Quaternions have 4 components so I don't know what you are even trying to do.

  2. Each value does not necessarily store rotation around a single axis so editing a specific value might give you strange results.

Maybe you want Euler Angles:

 var angleA : Vector3 = new Vector3 ( x , y , z );
 var angleB : Vector3 = new Vector3 ( x ,  y, z );

 var angleC : Vector3 = new Vector3 ( angleA.x , angleB.y , angleA.z);
 transform.eulerAngles = angleC;

or if you want to use Quaternions use the "*" operator to multiply them together:

 var rotationAngle : float = 90;
 var quatA = Quaternion.AngleAxis(rotationAngle , Vector3.forward);
 var quatB = Quaternion.AngleAxis(rotationAngle , Vector3.up);

 var quatC = quatA * quatB;
 //this will be rotate 90 degrees around the z axis and 90 degrees around the y axis.
  transform.rotation = quatC;

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 Xav_m · May 21, 2011 at 04:37 PM

Thanks!

I think I missunderstood quaternions.

I have a function that lines a prefab with an irregular terrain. Works ok as long as terrain is flat, when slopes occur some geometry gets into terrain mesh, so I get some cuts. I need to align the prefab to the last positioned one, to form a continous skidmark, so I thought on getting the normal of the terrain and aligning X,Z to terrain and Y to lookat previous prefab.

So back to question, how do I get a component from a quaternion?

I tried:

 Debug.Log ("rotx: "+rotationQ[ 0 ]);

and get different result from

 inspector value: 331.4471
 debug log: -0.2466001

Thanks again.

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 Bunny83 · May 21, 2011 at 05:16 PM 0
Share

You should read Peter's answer carefully. A Quaternion is a 4-dimensional representation of a rotation in 3d-space. They are used to prevent errors or impossible rotations in some special cases. The components are parts of a complex number system. You don't have to deal with the 4 components at all. The 3 numbers that you can see in the inspector are the localEulerAngles.

avatar image Bunny83 · May 21, 2011 at 05:17 PM 0
Share

Oh, and don't post comments as answers... You can edit your question at any time or use comments to comment an answer.

avatar image Xav_m · May 21, 2011 at 05:37 PM 0
Share

Thanks for the explanation on quaternions as well as the localEulerAngles.

I'm sorry, missed the "comment button".

avatar image Owen-Reynolds · May 21, 2011 at 08:10 PM 0
Share

Cheap method: place an empty on the end of the skid mark. To make a new skidmark. place it on the empty for the old one, and do a lookAt to the tire. A lineRender also has possibilities.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Combining two Quaternion Slerps on an object 1 Answer

Two scripts rotating the same object 1 Answer

combine / convert rotations (Quaternion and Vector3) 1 Answer

Directional booster 1 Answer

Mimic other object's rotation on one axis (with offset) 0 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