RayCast Oscillation

Hi, I have this problem, I have a red cube shooting a RayCast to a blue cylinder and at the hit.point (slightly back) I have a yellow cube, but when I rotate the red cube 90 degrees, wait, then rotate back 90 degrees the yellow cube shakes while the red cube is rotating, the yellow box has no collider attached, can anyone tell me why it does this please instead of staying still, I’ve posted the test code I’m using and a picture, thanks.

``````#pragma strict

var blueCylinder : Transform;

private var yellowBox : GameObject;
private var hit : RaycastHit;
private var rotating = false;
private var x : boolean;
function Start(){

yellowBox = GameObject.Find("B-Cube");
}

function Update(){

ray();

if(!x){
rotate();
}
}

function ray(){

if(Physics.Raycast (transform.position, blueCylinder.position - transform.position, hit, Mathf.Infinity)){

Debug.DrawRay (transform.position, blueCylinder.position - transform.position, Color.blue);

yellowBox.transform.position = hit.point + Vector3(0,0,-1);
yellowBox.transform.rotation = Quaternion.identity;
}
}

function rotate(){

x = true;
RotateObject(transform, Vector3.up*-90, 1.0);
yield WaitForSeconds (4);
RotateObject(transform, Vector3.up*90, 1.0);
yield WaitForSeconds (4);
x = false;
}

function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) {
if (rotating) return;
rotating = true;

var startRotation = thisTransform.rotation;
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
var t = 0.0;
var rate = 1.0/seconds;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}

rotating = false;
}
``````

Problem solved. I had the yellow cube a child of the red cube, separated and works correctly now.