# != isn't working consistently.

the != operator simply isn’t working, i don’t see why not:

``````		if (Input.GetKey (KeyCode.W) && platform.transform.localEulerAngles.z != 25f)
{
platform.Rotate(0f, 0f, 1f);
}

if (Input.GetKey (KeyCode.S) && platform.transform.localEulerAngles.z !=330f)
{
platform.Rotate(0f, 0f, -1f);
}
``````

basically, for whatever reason, it is flat-out not working consistently, i don’t know why, sometimes it works, sometimes it doesn’t.

Well, I’m 100% sure that not equals works correctly. Perhaps the z value never actually equals 25?

Also, floating point numbers are never exactly precise by their nature, so it’s usually a bad idea to check for equality.

Looking at your code though, you probably wanted to do something like >= and <= because it seems like you want to use 25 and 330 as bounds. My understanding of your logic is “as long as its not less than 25 degrees, W should subtract 1 and as long as its not greater than 330 degrees, A should add 1.”

EDIT: After discussing it in the comments, because equality testing on floats is a bad idea, here’s [untested] code to do what you want.

``````if( platform.transform.localEulerAngles.z <= 25 ||  platform.transform.localEulerAngles.z >= 330){
if(Input.getKey(KeyCode.W)){
platform.Rotate(0f, 0f, 1f);
}
if(Input.getKey(KeyCode.S)){
platform.Rotate(0f, 0f, -1f);
}

}
``````

Checking floats for equality is a crapshoot at best.

``````//BAD
if (someFloat == 3f) {
...
}

//BETTER
float difference = Mathf.Abs(someFloat - 3f);
if (difference < 0.1f) {
...
}
``````

Unity provides Mathf.Approximately, but I prefer to control my expected precision a given task.

As an aside, you’ll get more consistent results if your rotation is expressed in terms of units-per-second.

``````//rotate 1 degree per frame (varies with FPS)
transform.Rotate(0f, 0f, 1f);

//rotate 100 degrees per second (independent of FPS)
transform.Rotate(0f, 0f, 100f * Time.deltaTime);
``````