I know this one line is pretty self explanatory, but i'm having trouble understanding the order it's placed in
Quaternion referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);
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
Vector3 CameraDirection = camera.forward;
CameraDirection.y = 0.0f; //kill y
Quaternion referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);
//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;
}
https://www.youtube.com/watch?v=lnguV1v38z4
Here is the link for the tutorial right here. The part I'm talking about starts at 8:20 in the video.
↧