How do I call FromToRotation but with a desired up vector (like LookRotation can do)?

I want to call FromToRotation with a desired up vector to avoid Z axis rotation. LookRotation allows us to pass in our desired up vector but FromToRotation doesn’t.

Is there an algorithm or series of function calls I can do to achieve the desired effect?

If the two Directions that you pass into FromToRotation are perpendicular to the desired Up Vector then it will give you back a Quaternion that represents a rotation around that Vector. If one or more of the directions you passed in was not perpendicular to the desired Up Vector it would be impossible to generate a Quaternion that both rotates around the Up Vector and rotates the start vector to the end vector. In short, it’s up to you to pass in vectors that are perpendicular to the desired up vector.

Here’s one way you could do it that assumes your desired Up Vector is in-fact WorldSpace Up or (0, 1, 0):

Quaternion rotation = Quaternion.FromToRotation(
    new Vector3(fromDirection.x, 0, fromDirection.z),
    new Vector3(toDirection.x, 0, toDirection.z)
);

By zeroing out the y component in both Directions I guarantee that the rotation between them is around the y-axis.

I’ve found the solution in case anyone is curious, and it’s so simple it makes me wonder why I can’t find the answer online (maybe it’s too obvious that no one bothers asking it). Multiply the resulting FromToRotation quaternion with Vector3.forward. Then, call LookRotation(resultingVector, Vector3.up).