#How do i limit the x axis

1 messages · Page 1 of 1 (latest)

pale merlin
#

Pretty much the same way you did the y axis - check the axis' value and reset it to the limit if necessary.

#

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.

ashen matrix
#

o

#

ok

#

it works thanks!

tame sundial
#

Clamp is very useful. It clamps the given value (argument #1) between Min and Max (argument #2 and #3)

ashen matrix
#

aha

#

i found a found a random tut on yt

#

it was about 3 years old

tame sundial
#

For example: Mathf.Clamp(1, 1, 10) means the value (1) can only be in the borders of 1 and 10

#

:)

ashen matrix
#

alright im gonna get back to programing

tame sundial
#

its basically exactly same as range, but not in the unity editor and not changeable in the unity editor