Movement Position Being Equal to Int

I wasn’t exactly sure how to title this, however I will explain what I mean. I am trying to make my game object move using:

transform.translate(Vector2.up * moveSpeed * time.deltaTime);

Now what I want to do next is what is causing some trouble. I would like the object to continue moving until it hits the Y value of 1, and then turn left. I almost have that working. See it WILL work if I use >= 1, because it skips over the value of 1 (not moving by choppy ints). Even if I try changing it to == 1.0f it still won’t work as I guess the object is moving too quickly and skips over some values. We’ve tried re-positioning it in the >= block of code but that bugs out and doesn’t work very well.

If you have any thoughts or possible solutions that would be great! Thanks! :smiley:

Code ex:

if (transform.position.x <= -2 && transform.position.y < -1) {
    transform.Translate(Vector2.up * playerSpeed * Time.deltaTime);
}
else if (transform.position.y <= -4)
{
    transform.Translate(Vector2.left * playerSpeed * Time.deltaTime);
}

The solution you have is fine. It’s almost impossible for the value to land perfectly as an integer.

It is normal behaviour but what you can do to correct that is : when you know your transform is above -1 just clamp it to that value like this :

`

if (transform.position.x <= -2 && transform.position.y < -1) {
         transform.Translate(Vector2.up * playerSpeed * Time.deltaTime);
         if(transform.position.y > -1)                      //Check if it has passed -1
               tranform.position.y = -1;                     //Clamp it
     }
     else if (transform.position.y <= -4)
     {
         transform.Translate(Vector2.left * playerSpeed * Time.deltaTime);
     }

`

This should fix your problem.