# Time.deltaTime affects Vector3 comparison.

I have a platform that would move towards a point, waiting 2 seconds, returning to the starting point, waiting other 2 seconds and restarting the cycle. Here the script:

``````Vector3 lowPosition, highPosition, direction;
public float hight, speed, waitingTime;
public string startingDirection;
bool stop;

void Awake(){
stop = false;
if (startingDirection == "up") {  //to define the starting direction
lowPosition = transform.position;
highPosition = new Vector3 (transform.position.x, transform.position.y + hight, transform.position.z);
direction = highPosition;
}
else {
lowPosition = new Vector3(transform.position.x, transform.position.y - hight, transform.position.z);
highPosition = transform.position;
direction = lowPosition;
}
}

void Update(){
if (!stop) {
if (transform.position == highPosition) { //(transform.position * Time.deltaTime == highPosition * Time.deltaTime --->most of the times it works
direction = lowPosition;
StartCoroutine (Wait ());
} else if (transform.position == lowPosition) { //working in the same way
direction = highPosition;
StartCoroutine (Wait ());
}
transform.position = Vector3.MoveTowards (transform.position, direction, speed * Time.deltaTime);
if (playerTouched)
}
}
``````

Three days ago it worked, but not today: when it reaches the highPoint or lower one it stops, but it doesn’t start moving and doesn’t run the IEnumerator method. Problem is the Time.deltaTime that is not completely exact in calculation and makes the obvious control false. In fact if I insert (transform.position * Time.deltaTime == highPosition * time.DeltaTime) rather than simply (transform.position == highPosition) in the if, most of the times it works. But at the first false, the platform doesn’t move. Placing even more platform in the scene, each of them assums a different behaviour(someone stops at the second cycle, the other one at the first etcetera) in a constant way. How can I fix it?

Never compare floats for equality.

Change `transform.position == highPosition` to `transform.position >= highPosition`
and `transform.position == lowPosition` to `transform.position <= lowPosition`