My first person camera, goes all over the place after enabling weapon collider

Hello, I have a first person script, and it work good, but however if i enable another collider, then it acts all crazy? also i have tried disabling the script of the first person camera, and then the crazy movement stops, but when i enable it again it goes again. Meaning that it not a collider issue. Here is a GIF of the problem And here is the script of the first person camera :

   using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
  
     public class ScanningRobotTestCamera : MonoBehaviour {
         //ThirdPersonCamStuff VVVVVVVVVVVVVVVVVVVVVVVVVVVV
         public const float Y_AXIS_MIN = 0.00f;
         public const float Y_AXIS_MAX = 50.00f;
         [Space]
         [Header("ThirdPlayerCamStuff")]
      
         public Transform LookAtTarget;
         public Transform CameraTransform;
      
         private Camera cam;
      
         public float Speed;
         public float distance;
         public float currentX;
         public float currentY;
         public float sensetivityX;
         public float sensetivityY;
         public bool Once;
         public bool SecondOnce;
         //ThirdPersonCamStuff ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         //FirstPersonCamStuff VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
         [Space]
         [Header("FirstPlayerCamStuff")]
         public float ClampFirstPersonMin;
         public float ClampFirstPersonMax;
         public GameObject Arms;
         public GameObject RobotModel;
         public GameObject PlayerMdel;
      
         public Vector2 MouseLook;
         public Vector2 SmoothV;
         public float sensitivity;
         public float smoothing;
         public Vector2 md;
         public bool Escape;
         public GameObject Character;
         public GameObject NormalParent;
         //FirstPersonCamStuff^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      
         [Space]
         [Header("Other")]
         public string ChangeCamsKey;
         public int DiffrentCamsNumber;
         public int NumberOfDiffrentCams;
         public enum DiffrentCams{FirstPerson,ThirdPerson};
         public DiffrentCams DiffCams;
      
         // Use this for initialization
         void Start () {
          
             CameraTransform = transform;
         }
      
      
      
      
      
      
      
      
         void Update(){
             if (Input.GetKeyDown(ChangeCamsKey)){
                 if (DiffrentCamsNumber == NumberOfDiffrentCams){
                     DiffrentCamsNumber = 0;
                 }
                 DiffrentCamsNumber += 1;
                 if (DiffrentCamsNumber == 1){
                     DiffCams = DiffrentCams.FirstPerson;
                 }
                 if (DiffrentCamsNumber == 2){
                     DiffCams = DiffrentCams.ThirdPerson;
                 }
             }
          
          
          
          
          
             //FirstPersonCamStuff VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
             if(DiffCams == DiffrentCams.FirstPerson){
                 Arms.transform.parent = transform;
                 RobotModel.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
                 if(!SecondOnce){
                     //                transform.localEulerAngles = Vector3.zero;
                     Arms.transform.localEulerAngles = new Vector3(0,0,Arms.transform.localEulerAngles.z);
                     SecondOnce=true;
                 }
                 Once=false;
                 gameObject.transform.parent = Character.transform;
                 gameObject.transform.localPosition = new Vector3(0,2.6399991f,0);
                 md = new Vector2(Input.GetAxisRaw("Mouse X"),Input.GetAxisRaw("Mouse Y"));
                 print (md);
                 md = Vector2.Scale(md,new Vector2(sensitivity * smoothing, sensitivity * smoothing));
                 SmoothV.x = Mathf.Lerp (SmoothV.x, md.x, 1f / smoothing);
                 SmoothV.y = Mathf.Lerp (SmoothV.y, md.y, 1f / smoothing);
                 MouseLook += SmoothV;
                 MouseLook.y = Mathf.Clamp (MouseLook.y, ClampFirstPersonMin,ClampFirstPersonMax);
                 Arms.transform.localPosition = new Vector3(-1.85f,-2,1.31f);
                 transform.localRotation = Quaternion.AngleAxis (-MouseLook.y, Vector3.right);
                 Character.transform.localRotation = Quaternion.AngleAxis (MouseLook.x,Character.transform.up);
             }//FirstPersonCamStuff^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             //ThirdPersonCamStuff VVVVVVVVVVVVVVVVVVVVVVVVVVVV
             if(DiffCams == DiffrentCams.ThirdPerson){
                 Arms.transform.parent = PlayerMdel.transform;
                 RobotModel.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
                 Arms.transform.localPosition = Vector3.zero;
                 if(!Once){
                     MouseLook.y = 0;
                     Arms.transform.localEulerAngles = Vector3.zero;
                     Once=true;
                 }
                 SecondOnce=false;
                 gameObject.transform.parent = NormalParent.transform;
              
                 transform.localRotation = Quaternion.AngleAxis (-MouseLook.y, Vector3.right);
                 //        Character.transform.localRotation = Quaternion.AngleAxis (MouseLook.x,Character.transform.up);
                 if(Input.GetKey(KeyCode.Mouse1)){
                     print(Vector3.back);
                     currentY +=    Input.GetAxis("Mouse Y") * Speed;
                     currentX +=    Input.GetAxis("Mouse X") * Speed;
                     currentY = Mathf.Clamp (currentY, Y_AXIS_MIN, Y_AXIS_MAX);
                 }}//ThirdPersonCamStuff ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         }
      
         // Update is called once per frame
         void LateUpdate () {
             //ThirdPersonCamStuff VVVVVVVVVVVVVVVVVVVVVVVVVVVV
             if (DiffCams == DiffrentCams.ThirdPerson) {
                 Vector3 dir = new Vector3 (0, 0, -distance);
                 Quaternion rotation = Quaternion.Euler (currentY, currentX, 0);
                 CameraTransform.position = LookAtTarget.position + rotation * dir;
                 CameraTransform.LookAt (LookAtTarget);
             }//ThirdPersonCamStuff ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         }
     }

You’re not enabling/disabling the script in that GIF. You’re toggling the Collider on the arms.

Since you’re controlling the arms’ movement with the script, those colliders will push around any other rigidbodies they come into contact with, including that of the player controller itself.

It is a collider issue.

But i have different layers, also here is a GIF where i disable the script, and you will see that it stops spinning. Also when i disable the collider in the other GIF, it still spins.

will anybody reply, im sorry but this is a really bad problem because i can’t continue on my project…

I agree with Schneider21. Also in your 2nd GIF, I don’t see where the camera is spinning then stops when you disable the script as you claim. All I see is you enabling a collider. It is also so low res it is hard to see clearly what is happening at all.

Oops wrong gif sorry, also sorry for bad quality but hopefully you will be able to see this GIF.
Also if you notice in the first gif, the camera is moving not the arm, and the camera has no collider

Your update is suspicious to me. It looks like you are doing a bunch of set up stuff, plus some lerping, and some position setting? I think you need to take a critical look at what you’ve got going on there.

As a nit pick, you shouldn’t set the transform parent the way you are doing it, you should use SetParent() instead.

Habitblaba, okay i will refactor my code in the update section, and then i will check if it works.

I’m also interested to know what happens if you comment out the mouse look code.
My theory is that you’re getting the mouse location while the mouse is off screen (clicking the check box), then constantly trying to look to the right, because that’s where the mouse is.
In order to do mouse look, you’re going to want to center the mouse. Then, in update, check how far away from center it moved (and in which direction), then move the camera by an appropriate amount. Finally, re-center the mouse.

Yes but the weird thing is after enabling collider it starts spinning and won’t stop until i restart game or i disable the script(but it starts again if i enable it again)

P.S: I havent refactored the code yet

I think what we’re going to find is that there are multiple things wrong here, so we’re going to have to try a whole bunch of stuff.

Edit:
Try something for me. Do everything you do in the first gif you posted, except don’t actually toggle the box collider. So start the scene, look around a bit, pause and switch to scene view… then unpause and switch back to game view.
What happens?

Im so happy, i solved it, ok i will try to explain what is.
So after doing a little bit of debugging i figured out the “Character.transform.localRotation = Quaternion.AngleAxis (MouseLook.x,Character.transform.up);” was where the problem was causing, so after printing ever variable, i figured out that after enabling the collider, the “Character.transform.up” was going from (0.0,1.0,0.0) to (insert random number -1 to 1 here,insert random number -1 to 1 here,insert random number -1 to 1 here), so i just replaced “Character.transform.up”, to “Vector3.up”, and now it works :smile:. Thank you Habitblaba, Joe-Censorned , and Schneider21**.**