Collider causing object to spin when moving

Hi

I’m working on a script that moves an object up and down.

        public float bobSpeed = 1.0f;
        public float bobAmount = 0.5f;
        private Vector3 startingPosition;
        private float piAmount = Mathf.PI * 2;
        private float effectTime = 0;
        
        private void Start()
        {
            startingPosition = transform.localPosition;
        }

        private void Update()
        {
            effectTime += Time.deltaTime * bobSpeed;
            Debug.Log(Time.deltaTime);
            Vector3 moveAmount = transform.TransformDirection(new Vector3(0.0f, bobAmount * Mathf.Sin(piAmount * effectTime), 0));
            transform.localPosition = startingPosition + moveAmount;
        }

The object the script is attached to has a box collider, if the collider is enabled after a few seconds the object starts to quickly spin around. If I disable the collider it works correctly.

What could be happening here?

I have partially solved it by setting isKinematic to true while the object is in a “bobbing” state. I’m still curious though why having a rigid body (its this component and not the collider) causes the object to spin I’m changing the localposition.