About transform.forward

Set transform.right & up with Quaternion.FromToRotation, but set transform.forward with Quaternion.LookRotation.

Why?

In Unity, Quaternion.FromToRotation is used to create a rotation that rotates from one direction to another, while Quaternion.LookRotation creates a rotation that looks along a specified forward direction.

When you use Quaternion.FromToRotation, you are specifying two vectors: the initial direction and the target direction. This function then calculates the rotation needed to align the initial direction with the target direction. It’s particularly useful when you want to align one axis of an object with a specific direction without affecting the other axes.

On the other hand, Quaternion.LookRotation is useful when you want an object to face a specific direction. You provide the forward direction you want the object to face, and the function calculates the rotation needed to achieve that orientation.

So, if you want to set the transform.right and transform.up directions, you might use Quaternion.FromToRotation to rotate from the current right and up directions to the new ones. For transform.forward, you would use Quaternion.LookRotation to set the forward direction of the object.

Here’s an example:

Vector3 newRight = ...;  // your new right direction
Vector3 newUp = ...;     // your new up direction
Vector3 newForward = ...; // your new forward direction

transform.rotation = Quaternion.FromToRotation(transform.right, newRight) *
                     Quaternion.FromToRotation(transform.up, newUp) *
                     Quaternion.LookRotation(newForward);

This way, you’re combining the rotations for right and up using Quaternion.FromToRotation and then adjusting the forward direction with Quaternion.LookRotation.