Child object jumps back and forth every frame

So I’m assuming the problem is the fact that it’s a childed object, but please correct me if I’m wrong. Here’s my code:

		if(gun[curWeapon] != null)
			{
			//float x = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.x, 180f +   (rotation.x - Camera.main.transform.eulerAngles.x), 0.8f) - 180f;
			float y = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.y, 180f + (rotation.y - transform.localEulerAngles.y), 0.6f);
			float z = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localEulerAngles.z, 180f - ((rotation.y - transform.localEulerAngles.y)/2f), 0.6f);
			gun[curWeapon].gunObject.transform.localEulerAngles = new Vector3(0f, y, z);

			float a = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localPosition.x, 0f + (position.x - transform.localPosition.x), 0.1f);
			float c = Mathf.MoveTowards(gun[curWeapon].gunObject.transform.localPosition.z, 1f + (position.z - transform.localPosition.z), 0.1f);
			gun[curWeapon].gunObject.transform.localPosition = new Vector3(a, 0f, c);
			}

		position = transform.localPosition;
		rotation = new Vector3(Camera.main.transform.eulerAngles.x, transform.localEulerAngles.y, 0f);

I’ve made sure that gun[curWeapon].gunObject is not being affected by any other part of the script, it just jumps back and forth.

The script is an experimental gun sway and movement script.

Thanks in advance! :wink:

Not exactly an answer to the original question, but I fixed it by having it do what I wanted it to do.

Instead of doing anything with float a and c, I did this:

gun[curWeapon].gunObject.transform.localPosition = Vector3.Lerp(gun[curWeapon].gunObject.transform.localPosition, new Vector3(0.2f, -0.3f, 0.6f) - rigidbody.velocity/100, 0.5f);

EDIT: Full code

		if(gun[curWeapon] != null)
			{
			y = Mathf.MoveTowards(y, 180f + (rotation.y - transform.localEulerAngles.y), 1f);
			z = Mathf.MoveTowards(z, 180f - (rotation.y - transform.localEulerAngles.y), 1f);
			gun[curWeapon].gunObject.transform.localEulerAngles = new Vector3(0f, y, z);
			gun[curWeapon].gunObject.transform.localPosition = Vector3.Lerp(gun[curWeapon].gunObject.transform.localPosition, new Vector3(0.2f, -0.3f, 0.6f) - rigidbody.velocity/100, 0.5f);
			}

		position = transform.localPosition.normalized;
		rotation = new Vector3(Camera.main.transform.eulerAngles.x, transform.localEulerAngles.y, 0f);