stopping the gameObject if it is out of specified bounds.

I have a certain condition in which a gameObject can be moved only in x axis.I am using mouse x delta change as input (Input.GetAxis(“Mouse X”)) multiplied by some sensitivity. i have defined boundary value for x, so that it is clamped.
the problem is that the gameObject moves some values greater than boundary value then resets back to boundary position. it is not stopping immediately at that point.

  1. using physics calculations in Fixedupdate().
  2. moving using rigidbody.MovePosition() method.

Use Mathf.Clamp to achieve this right before using it for moving.

//Mathf.Clamp: clamps/confines the variable to the range you supply
x_move = Mathf.Clamp (x_move, MINIMUM_VALUE, MAX_VALUE);

//clamp it after you've done all calculations such as a multiplier ect.

// do whatever you want as far as moving the object.