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


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

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.

You have to do Quaternion * Vector3

Vector3 * Quaternion gives an error

To add to the Bunny83 response, if you are using unity DOTS stacks, you will most likely need the following syntax when using Unity.Transforms:

float3 targetForward = math.mul(targetRot, Vector3.forward);

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