rotation to axis conversion problem?

Hello,
I’m trying to do a “local rotation” conversion to a Vector3 axis. What i’m trying to do is set a ConfigurableJoint.axis, to be aligned exactly as the rotation of one of my gameobject’s children.

so i get the child’s local rotation, and extract the axis from it, applying it to the configurable joint:

					var angle = 0.0;
					var axis = Vector3.zero;
mychild.transform.localRotation.ToAngleAxis(angle, axis);
myJoint.axis = axis;

the result is a Vector3(0.9,0.0,-0.4) but using it to set the configurableJoint.axis really doesn’t give me the direction it should…

any ideas why this is happening?
trying by hand some rotations, the joint axis seems to be right at (1,0,-1), for this particular example.

or is there any other more efficient way to get this rotation to a CJ axis?

thank you!

so, after some headbanging against the wall, i got the answer to this, in case anyone else looks for it:

to get the LOCAL direction of a gameobject’s child’s axis (let’s say, the forward direction)
the line is

var myaxis : Vector3 = transform.InverseTransformDirection(mychild.transform.forward);

from Unity - Scripting API: Transform.InverseTransformDirection

this will give the relative direction in respect to the parent’s direction, which you can then use to set something like a configurable joint axis.

:slight_smile: