# Quaternion FromToRotation Confusion

I know this one line is pretty self explanatory, but i’m having trouble understanding the order it’s placed in

Basically the forward direction of the camera is supposed to be set to be the same rotation as the Vector3.foward (I guess because it was altered so it couldn’t use y…) Anyways I’m a little bit confused by the order its in. Why isn’t it set FROM the Camera’s rotation TO the Vector3.forward. It looks like it’s set up backwards.

public void StickToWorldspace(Transform root, Transform camera, ref float directionOut,ref float speedOut)
{
Vector3 rootDirection = root.forward;
Vector3 stickDirection = new Vector3(horizontal, 0 , vertical);

speedOut = stickDirection.sqrMagnitude;

//Get Camera Rotation

//Convert joystick input in Worldspace coordinates
Vector3 moveDirection = referentialShift * stickDirection;
Vector3 axisSign = Vector3.Cross (moveDirection, rootDirection);
Debug.DrawRay (new Vector3(root.position.x, root.position.y + 2f, root.position.z),moveDirection, Color.green);
//Debug.DrawRay (new Vector3(root.position.x, root.position.y + 2f, root.position.z),axisSign, Color.red);
Debug.DrawRay (new Vector3(root.position.x, root.position.y + 2f, root.position.z),rootDirection, Color.magenta);
//Debug.DrawRay (new Vector3(root.position.x, root.position.y + 2f, root.position.z),stickDirection, Color.blue);

float angleRootToMove = Vector3.Angle(rootDirection, moveDirection) * (axisSign.y >= 0 ? -1f : 1f);    //Mathf.Sign(Vector3.Dot(axisSign, transform.up *-1));

angleRootToMove /= 180f;
directionOut = angleRootToMove * directionSpeed;
}
Here is the link for the tutorial right here. The part I'm talking about starts at 8:20 in the video.

First the line rotation:

…is creating a rotation that will take some facing positive ‘z’, and rotate it so that it is facing the same direction as the camera. So if after I did the line above, I did:

Vector3 v = referentialShift * Vector3.forward;

…the resulting ‘v’ would be pointing the same direction as the camera…that is ‘v’ and camera.forward would be the same.

I’m seeing this code out of context, but it appears that he wants the joystick input to be relative to the camera. For example, if you push the stick forward, he wants the forward movement to be on forward of the camera. So he execute this line:

Vector3 moveDirection = referentialShift * stickDirection;

This rotates the ‘stickDirection’ around so that ‘moveDirection’ will be relative to the camera, not to the world.

forward direction of the camera is
supposed to be set to be the same
rotation as the Vector3.foward

No, it is the other way around. Nothing here is rotating the camera. He is changing Joystick input so that it is relative to the camera. So that if he pushed the joystick to the left, the moveDirection would be to the camera’s left, not the world left.