title: Mathf.clamp() function in Unity
body: <p>I have a Cube(Player) in my game scene. I have written a C# script to constrain the movement(using <code>Mathf.Clamp()</code>) of the Cube so it does not leave the screen.</p>
  
  <p>Below is my <code>FixedUpdate()</code> method from the Script</p>
  
  <pre><code>private void FixedUpdate()
      {
          float moveHorizontal = Input.GetAxis("Horizontal");
          float moveVertical = Input.GetAxis("Vertical");
  
          Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
          rb.velocity = movement * speed;
  
          rb.position = new Vector3(
              Mathf.Clamp (rb.position.x, x_min, x_max),
              0.5f,
              Mathf.Clamp(rb.position.z, z_min, z_max)
              );
  
      }
  </code></pre>
  
  <p>Values of <code>x_min</code>, <code>x_max</code>, <code>z_min</code>, <code>z_max</code> are  -3, 3, -2, 8 respectively inputted via the unity inspector.</p>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>The script is working fine but my player(Cube) can move up to -3.1 units in negative <code>X-AXIS</code> (if I keep pressing the left arrow button) which is 0.1 units more in negative <code>X-AXIS</code>(This behavior is true for other axes too). It obviously clamps -3.1 to -3 when I stop pressing the button.</p>
  
  <p><a href="https://i.stack.imgur.com/Tp3QX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tp3QX.png" alt="enter image description here"></a></p>
  
  <ul>
  <li>Why is this happening? Why doesn't it(<code>Mathf.Clamp()</code>) restrict the Cube to -3 units in first place?</li>
  <li>Why am I getting that extra 0.1 units?</li>
  <li>And Why is this value 0.1 units only? Why not more or less?</li>
  </ul>