Rotate the flashlight into the direction the player looks

Ive got a 3d first person charater that has a flashlight as a child object.
The flahslight has a script attached and im attempting to rotate the flashlight in the direction the player looks and then when they stop giving look input have it lerp back to center.

Please assist, oddly enough ChatGPT is pretty unhelpful.

private void Update()
    {
        if (_largeLight.enabled && _smallLight.enabled)
        {
            if (_playerLook.LookInput != Vector2.zero)
            {
                // rotate flashlight on x and y based on lookinput
            }
            else
            {
                // Lerp back to the current rotation of the main camera
                Quaternion currentCameraRotation = _mainCamera.rotation;
                transform.rotation = Quaternion.Lerp(
                    transform.rotation,
                    currentCameraRotation,
                    Time.deltaTime * _returnLerpSpeed
                );
            }
        }
    }

You could just set the flashlight’s transform.forward to the camera’s transform.forward.

I cant because i want it to lead ahead while there is input and then lerp back to center
I know i need to reference the camera rotation to determine relatively which way to lead the flashlight
I also know i need the player look input

problem is whenever i try to lerp in the direction im looking i get weird behavior. the closest Ive had it was it was leading horizontally but didnt do anything vertically. I didnt include it because I feel like its totally the wrong way.

What kind of weird behavior?

Okay this code works on the y but just not on the x, it lags behind on the x

[SerializeField]
    private float rotationOffsetAngle = 10f; // Smaller angle for natural leading effect

    [SerializeField]
    private float _maxLerpSpeed = 2f;

    [SerializeField]
    private float _returnLerpSpeed = 2.5f;

private void Update()
    {
        if (_largeLight.enabled && _smallLight.enabled)
        {
            Vector2 lookInput = _playerLook.LookInput;

            // Check if the look input is above a small threshold to avoid jittering
            if (lookInput.magnitude > 0.1f)
            {
                // Calculate small rotation offset for natural leading
                float xRotation = lookInput.y * rotationOffsetAngle;
                float yRotation = lookInput.x * rotationOffsetAngle;

                // Create target rotation slightly ahead based on camera's rotation
                Quaternion targetRotation =
                    _mainCamera.rotation * Quaternion.Euler(-xRotation, yRotation, 0);

                // Smoothly rotate using Slerp for better handling of larger changes
                transform.rotation = Quaternion.Slerp(
                    transform.rotation,
                    targetRotation,
                    Time.deltaTime * _maxLerpSpeed
                );
            }
            else
            {
                // Lerp back to the current rotation of the main camera when look input is near zero
                transform.rotation = Quaternion.Slerp(
                    transform.rotation,
                    _mainCamera.rotation,
                    Time.deltaTime * _returnLerpSpeed
                );
            }
        }
    }

Are you sure that rotationOffsetAngle is actually necessary? That seems redundant since you are already using the slerp to limit the camera’s movement per frame.

Or, if the y axis is working properly, have you tried a different value for the x axis?

Also, you might be interested in: