CubeFloatLR Script

I wrote a script modifying a very useful one that I wrote to make a Cube float up and down. This script is supposed to make the cube float left and right, but for some reason when it gets all the way to the right it just sits there and quivers. Can someone take a look at my script and tell me what’s wrong? Thanks! :wink:

var min = -4.4;
var max = -12;
var right = true;

function Update () {
	if (transform.position.x < min) {
		right = true;
	}
	if (transform.position.x > max) {
		right = false;
	}
	if (right == true) {
		transform.position += Vector3.right * Time.deltaTime;
	}
	if (right == false) {
		transform.position += Vector3.left * Time.deltaTime;
	}	
}

should var max be positive 12? right now you’re saying if it’s less than -4.4 right is true and if it’s greater than -12 right is false.

ie: -10 is less than -4.4 and greater than -12.

Aren’t your ‘min’ and ‘max’ a bit inverted? I.e. the default values have ‘min’ larger than ‘max’

No, It’s floating from a negative point to a further in Negative point.

-10 is less than -4.4 and greater than -12. so right is true and false.

Ah. So how would I rewrite that to float between two negatives?

make your min -12 and your max -4.4

You guys are lifesavers. Thanks once more.