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.

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;

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.