- Home /

# 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);

**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.

Thanks for the answer! More 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.

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

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

```
Quaternion * Vector
```

That's what The_Mean_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 MVP matrix need to be multiplied in reverse order `P * V * M`

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

You have to do Quaternion * Vector3

Vector3 * Quaternion gives an error

THANK YOU!!!

THIS ONE DETAIL GAVE ME 5 HOURS OF GRIEF!!!

THANK YOU!!!

This caught me too. Multiplication 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.

Multiplication is commutative

True. *Multiplication* **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.

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.

**Answer** by edthered1009
·
Feb 18 at 11:05 PM

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

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

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

. 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![I] have two Quaternion[s,] and [I] need to convert the two Quaternion[s] to vector3[s.]

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Rotation, Vector3 and transform.forward 2 Answers

3D nested Turret Prefab Rotation 1 Answer

Problem with rotation around axis 1 Answer

Quaternion into Vector3 1 Answer

Learning about Vector algebra and manipulating an object 1 Answer