# Get Rotation Around transform.up

Hi there,

Would anybody happen to know how to get the rotation around a transform’s arbitrary up direction? For example, I’d like to be able to change an object’s up direction and get the relative Y component of the transform’s euler angle. I’m working in C#, but that shouldn’t make a difference in the technique.

What is rotated, and rotated off of what? There needs to be a start position.

The rotation around x,y,z axes is off another axis. Rotate off x-axis around the y-axis for instance. (On a side note, this interdependency of axes is actually one of the root causes of gimbal lock.)

So… say you wanted the rotation of the transform.forward vector around the transform.up vector, off… what? You can’t say transform.right… cause I’ll tell you what that is… it’s 90 degrees. You could say one of the axes, but that axes isn’t necessarily going to be orthogonal with the up vector, and could easily be equal to it… resulting in infinity for the answer.

You’re asking for something with out enough information.

Once you gather that information… here’s a function that returns an angle:

``````        /// <summary>
/// Find some projected angle measure off some forward around some axis.
/// </summary>
/// <param name="v"></param>
/// <param name="forward"></param>
/// <param name="axis"></param>
/// <returns></returns>
public static float AngleOffAroundAxis(Vector3 v, Vector3 forward, Vector3 axis)
{
Vector3 right = Vector3.Cross(axis, forward);
forward = Vector3.Cross(right, axis);
return Mathf.Atan2(Vector3.Dot(v, right), Vector3.Dot(v, forward));
}
``````