#How do i limit the x axis
1 messages · Page 1 of 1 (latest)
In any case, this can be done way shorter: cs Vector3 position = transform.position; // copy current position position.x = Mathf.Clamp (position.x, xMinLimit, xMaxLimit); // make sure that the position's x value is between xMinLimit and xMaxLimit position.y = Mathf.Clamp (position.y, yMinLimit, yMaxLimit); // make sure that the position's y value is between yMinLimit and yMaxLimit transform.position = position; // set the current position to the modified position
The Mathf.Clamp method does pretty much what you did manually - if the given current value is greater than the max, return the max, if it's smaller than the min, return the min, otherwise return the current value.
Clamp is very useful. It clamps the given value (argument #1) between Min and Max (argument #2 and #3)
For example: Mathf.Clamp(1, 1, 10) means the value (1) can only be in the borders of 1 and 10
:)
alright im gonna get back to programing
its basically exactly same as range, but not in the unity editor and not changeable in the unity editor