Apologize for the long post but I couldn’t make it shorter without sacrificing clarity.
My Hierarchy is as follows:
The Camera with the Brain, The Cinemachine Virtual Camera and the Player Gameobject
My settings on the Virtual Camera
What I am trying to achieve.
Objective 1: When there is no keyboard Input from user (WASD) but only mouse, the camera behaves like a free look camera.
This is currently already achieved in due to the Aim Vertical and Horizontal Range as shown below.
Objective 2: When the the camera reaches the edges of its horizontal view range limits (-85 to 85), as the user moves the mouse, the body rotates as well.
The code for the player rotation:
player.transform.Rotate(new Vector3(0.0f, Mathf.Sign(player.playerCamera.currentUserInput.x) * player.playerCamera.horizontalSpeed * Time.fixedDeltaTime, 0.0f), Space.Self);
After that Virtual Camera transform is aligned with the player transform. This is done since they are both on the same hierarchy level.
player.playerCamera.playerFPVCamera.transform.rotation = Quaternion.RotateTowards(player.playerCamera.playerFPVCamera.transform.rotation, player.transform.rotation, 360f);
The above method has a small problem.
The problem is while the Virtual Camera transform updates, the camera horizontal aim range remains aligned with the old transform for some reason as shown below.
This can be solved by a change in hierarchy levels as shown below and not using code to update camera transform rotation but I am not sure why the issue is cause in the first place.
The reason I do not wish to hierarchy as shown in the image above is because of the following objective.
Objective 3: When the player provides move input (WASD), the body aligns to the camera view and moves in that direction. If I hierarchy as in the image above, it causes a loop.
I am looking for a solution to achieve all my objectives. Any help will do