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
17
Question by malikcgcs · Aug 28, 2013 at 10:36 PM · vector3quaternion

How can I convert a Quaternion to a direction vector?

how i can Converting a Quaternion to a Direction Vector? i have two Quaternion and i need to convert the two Quaternion to vector3

and used the vectors in Quaternion.LookRotation(v3,v3)

Quaternion targetRot = Quaternion.LookRotation(myForward, hit.normal);

Quaternion targetRotation = Quaternion.LookRotation(targetDirection,hit.normal);

http://www.2shared.com/document/2djAJSdi/save.html

and

convert : Quaternion targetRot to vector3 targetRot
convert : Quaternion targetRotation to vector3 targetRotation

and used the new vector in: Quaternion AllTarget = Quaternion.LookRotation(vector3 targetRot, vector3 targetRotation);

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

3 Replies

· Add your reply
  • Sort: 
avatar image
55
Best Answer

Answer by Bunny83 · Aug 28, 2013 at 10:51 PM

A quaternion doesn't have a direction by itself. It is a rotation. It can be used to rotate any vector by the rotation it represents. Just multiply a Vector3 by the quaternion.

     Vector3 targetForward = targetRot * Vector3.forward;
     Vector3 targetUp = targetRot * Vector3.up;

What axis you need you have to figure out yourself since your code is just an abstract collection of code fragments.


Just to be absolutely clear for beginners: When you say "Which way is this Quaternion's up?" or "Which way does this Quaternion point forward?" what you probably actually mean is:

"If you take something which is standing straight up and forward, and apply the Quaternion to it, which way is the forward vector now?"

The example code above provides exactly that information.

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 TheMasonX · Dec 11, 2015 at 10:14 AM 0
Share

Thanks for the answer! $$anonymous$$ore importantly, thanks for the explanation/clarification of the underlying question in the second half; it really explains WHY this gives the intended result, rather than it being just another abstract operation that spits out the intended result.

avatar image AndyMartin458 · Nov 17, 2017 at 02:06 PM 0
Share

Sorry, I had it backwards, thank you for the explanation.

avatar image Bunny83 AndyMartin458 · Nov 17, 2017 at 04:08 PM 0
Share

Uhm, what do you mean? Your code example doesn't work. You have to do

 Quaternion * Vector

That's what The_$$anonymous$$ean_Fiddler said and that's what is written in my answer.

Quaternions basically work like a matrix multiplication which is also right to left. The $$anonymous$$VP matrix need to be multiplied in reverse order P * V * $$anonymous$$

avatar image
18

Answer by The_Mean_Fiddler · Jun 26, 2015 at 09:04 PM

You have to do Quaternion * Vector3

Vector3 * Quaternion gives an error

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 Mr-Mechanical · Aug 09, 2015 at 05:43 AM 0
Share

Wow. Thank you. This fixed my error!

avatar image Siloaman · Dec 15, 2015 at 10:22 PM 1
Share

THAN$$anonymous$$ YOU!!!

THIS ONE DETAIL GAVE $$anonymous$$E 5 HOURS OF GRIEF!!!

THAN$$anonymous$$ YOU!!!

avatar image Quasimodem · Jan 20, 2016 at 11:39 PM 0
Share

This caught me too. $$anonymous$$ultiplication is commutative, dammit!

It'd sure be nice if Unity would add

public static Vector3 operator *(Vector3 point, Quaternion rotation);

to the Quaternion class as well. Normally, you could do this yourself as an extension method, but unfortunately, C# doesn't allow you do make extension methods from operators. Bummer.

avatar image Eno-Khaon Quasimodem · Jan 21, 2016 at 04:42 AM 2
Share

$$anonymous$$ultiplication is commutative

True. $$anonymous$$ultiplication IS commutative.

Quaternion multiplication, however, is not commutative. When you multiply with a quaternion, the process can only behave in one manner.

See https://en.wikipedia.org/wiki/Commutative_property for details.

avatar image Bunny83 Quasimodem · Jan 21, 2016 at 06:00 AM 1
Share

Some additional information on the noncommutativity of quaternion multiplication. And just in time there's now a Numberphile video on quaternions ( extra bits ) which might help to get a better understanding of how they work.

avatar image
-2

Answer by edthered1009 · Feb 18, 2019 at 11:05 PM

Extremely simple. Quaternion.eulerAngles makes it a Vector3. :)

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 Bunny83 · Feb 18, 2019 at 11:23 PM 2
Share

This makes no sense. Yes, eulerAngles is represented as a Vector3 because it represents 3 angles, but this does not represent a direction vector.

avatar image edthered1009 Bunny83 · Feb 20, 2019 at 10:20 PM -1
Share

When did he ask for a direction vector? He asked for a Vector3.

[I] have two Quaternion[s,] and [I] need to convert the two Quaternion[s] to vector3[s.]

. Pay attention. Edit: Just realised he did mention direction vectors, but I think he is just using the wrong terms. Thanks for trying to help, though!

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

25 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 avatar image

Related Questions

What is Quaternion multiplied by a vector3? 0 Answers

making a camera that moves depending on mousepos.y 0 Answers

Help Rotating a Player 0 Answers

How to add 2 Quaternions. 2 Answers

How do I do operations with a Vector3 and a Quaternion? 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