LookRotation alternative
From Unify Community Wiki
Usage
This is an alternative for Quaternion.LookRotation. Instead of aligning the forward and up vector of the game object with the input vectors, a custom direction can be used instead of the fixed forward and up vectors.
destinationVector and destinationNormal are in world space. customForward and customUp are in object space.
Use destinationVector and destinationNormal as if you are using the default LookRotation function. Set customForward and customUp to the vectors you wish to use instead of the default forward and up vectors.
void lookRotationExtended(ref GameObject gameObjectInOut, Vector3 destinationVector, Vector3 destinationNormal, Vector3 customForward, Vector3 customUp){ //Set the rotation of the destination Quaternion rotationA = Quaternion.LookRotation(destinationVector, destinationNormal); //Set the rotation of the custom normal and up vectors. //When using the default LookRotation function, this would be hard coded to the forward and up vector. Quaternion rotationB = Quaternion.LookRotation(customForward, customUp); //Calculate the rotation gameObjectInOut.transform.rotation = rotationA * Quaternion.Inverse(rotationB); }