My objects keep on shaking

Hi

I am pretty new to Unity.

I am making a wall of cubes, I spread the cubes in a room and let them find their appropriate place in the wall. The cubes have colliders, they are affected by physics until they are a few units away from the wall where I turn on Kinematrics to be able to put them where they are supposed to go in the wall.

When they are in their position they keep on shaking lightly, even if they don't have any other cubes around them, I have tried a lot of different ways to make them stop but it seems nothing is working.

function Awake(){
main=GameObject.Find("Main");
script=main.GetComponent("initmovecube");
script.x=script.x+1;
x=script.x;
y=script.y;
z=script.z;
lessz=script.z-2;
cubenumber=name.Substring(0, name.Length - 7);
script.cubeint=parseInt(cubenumber);
Debug.Log(script.x+" "+x+" "+y+" "+z);
if (x==100) {
script.y=script.y+1;
y=script.y;
script.line=script.line+1;
}

}
pos=Vector3(x,y,z);
function Update () {
if(transform.position!=pos) {
transform.LookAt(pos);
transform.Translate(Vector3.forward*Time.deltaTime);
if (Input.GetKey(KeyCode.Q)){
Debug.Log("Key pressed.");
rigidbody.velocity=Vector3(0,0,0);
}
}
if (transform.position.z>=lessz) {
//Debug.Log("Cube nr: "+name.Substring(0, name.Length - 7)+" is on spot.");
gameObject.rigidbody.isKinematic = true;
transform.eulerAngles=Vector3(0,0,0);
transform.rotation=Quaternion.identity;
if (transform.position.y<pos.y ) {
}
}
if(transform.position==pos) {
gameObject.rigidbody.isKinematic = false;
rigidbody.velocity=Vector3(0,0,0);
if (rigidbody.IsSleeping()==false){
rigidbody.Sleep();
}

 }

Like Eric said, `(if transform.position == pos)` is probably causing your problem, so try making it an integer. However, that may not be accurate enough for your purposes, and why not just set the position directly? You might also consider when it gets close to the correct position, deleting it and instantiating a kinematic cube in its place. It's worked for me multiple times when trying to make something kinematic and it continues behaving strangely.

I think the main problem is you have things like "if (transform.position==pos)", but the position will never be exactly equal to pos, because of framerate variance and floating point imprecision. I don't quite understand what you're trying to do, but it seems like it would be much simpler just to set the position directly.

this is the way I solved the problem:

function Update () {
  if (inpos==false){
    ...
    dist=Vector3.Distance(pos, transform.position);
    if(dist<0.1) {
      transform.position=pos;
      inpos=true;
    }
  }
}