I can't aim properly in 3rd person with cinemachine and animation rigging

Hi guys i have a problem aiming in 3rd person with Cinemachine. Basically i’m trying to create a 3rd person shooter controller with two cinemachine, one for the normal movement and one for the aiming. The first works very good with a framing transposer in the body and a POV in the Aim, while for the second i can’t find good settings to adjust it. I tried to duplicate the first and mantain the same settings with a lower camera distance but the camera movement is not good at all. I also tried with 3rd person follow in the body, nothing in the aim and adjust it via script, but i can’t find a solution. I want the camera to rotate and look where the player is aiming. I’m using Control as videogame reference and trying to replicate it, so the player rotates by aiming on the x axis but stay put while aiming on the y axis. I specify that i’m using the new input system and the animation rigging, this is my script:

//Player rotation method
void PlayerRotation()
    {
        if (PlayerRifleAimingIdle.PlayerIsAiming)
        {
            transform.Rotate(new Vector3(0f, m_mouseDelta.x * m_aimSensivity, 0f));
        }

        if (IsMovementPressed && !PlayerRifleAimingIdle.PlayerIsAiming)
        {
            Quaternion targetRotation = Quaternion.LookRotation(m_moveDir);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.fixedDeltaTime * m_rotationSpeed);
        }
    }

//Player aiming method
void AimTarget()
    {
        if (PlayerRifleAimingIdle.PlayerIsAiming)
        {
            m_rig.weight = 1f;
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2f, m_mousePosition.y, 0f));
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                m_aimTarget.position = hit.point;
                m_crosshair.SetActive(true);
                m_crosshairPos.anchoredPosition = new Vector2(m_crosshairPos.anchoredPosition.x, m_mousePosition.y);
            }
        }
        else
        {
            m_crosshair.SetActive(false);
            m_rig.weight = 0f;
        }
    }

This is a video of my project so you can better see what i want to achieve:

Have you checked out this video? Tutorial that solves almost exactly this problem.

Hope it helps!

Yes i have seen this, but i have a problem with the vertical rotation of the camera. I put an empty object on the neck of the player and set it as follow target on the aim camera. Then inside the script i’m trying to clamp the values but it doesn’t work and i don’t know why. This is my code:

//Rotation of the target
m_aimFollowTarget.rotation *= Quaternion.AngleAxis(-m_mouseDelta.y * m_aimSensivity, Vector3.right);

//Rotation of the player
transform.Rotate(new Vector3(0f, m_mouseDelta.x * m_aimSensivity, 0f));

//Clamp of the vertical rotation 
Vector3 angles = m_aimFollowTarget.localEulerAngles;

if (angles.x > 89f)
{
angles.x = 89f;
}
else if (angles.x < -89f)
{
angles.x = -89f;
}

m_aimFollowTarget.localEulerAngles = angles;

NOT AN ENGINEER (anymore) ALERT:

Take a look at the documentation for localEulerAngle…it reads:

It seems to me that you’re relying on this property in a way that isn’t consistent with how it’s intended to be used. I believe that the code shown at around 3:50 in the tutorial addresses this case as well?