FPS Gun Attached To Camera Weirdness

Hello there! I have been having a problem lately with all of my Unity FPS projects. When I attach a gun to my main camera and look up, the gun moves up too much. This also happens when I look down. No scripts attached to the gun. I’ll show you some pictures. Please help!!

When looking up

When looking down

just so people know, all you have to do is make your players scale the same in all axis and it fixes this problem

The question is quite very old but I stuck up with the exact same problem and my issue was appeared because I changed the Scale-Y value in Transform of inspector of Player (First Person Controller), from 1 to 1.5. When I revert it to Scale-> 1, 1, 1 then everything start working fine.

If it’s moving up and down too much, then the only solution is to dampen the rotation. You CAN still maintain the relationship between parent-child / camera-weapon, but I would prefer doing something more along the lines of creating a separate script to manage rotation based off of the Camera.main.transform.rotation / eulerAngles, and unparenting the weapon completely.

The finished code should look something like:

            private Transform _cameraTransform = null;          // Caches the Camera's transform.

            GameObject _currentWeapon = null;           // Current weapon that's being used
            Transform _playerTransform = null;          // Player's Transform
            bool _canRotateWeapon = true;               // Can you rotate the weapon?
            float _rotationDampener = 0.5F;             // The amount that you want to multiply the rotation by. If it's rotating too much, keep this number < 1

            void Start()
            {
                _cameraTransform = Camera.main.transform;
            }

            void Update()
            {
                UpdateWeaponRotation(); 
            }

            // Updates the weapon's rotation
            void UpdateWeaponRotation()
            {
                if (_canRotateWeapon && _currentWeapon != null)           // If there's currently a weapon and you can rotate the weapon
                {
                    Vector3 desiredRotation = new Vector3(_cameraTransform.eulerAngles.x * _rotationDampener, _playerTransform.eulerAngles.y, _playerTransform.eulerAngles.z);   // Sets the rotation based off of the dampener * the Camera's X-axis. It might be the Z-axis instead so... don't get fully invested in using the X
                    _playerTransform.eulerAngles = desiredRotation; // Set the eulerAngles.
                }
            }

I added it to the comments, but you may require the Z-axis instead of the X-axis, based on your local rotation of the weapon. Heck, maybe even the Y-axis. Just mess around with it.