Stop character from moving.

Using the “First Person Controller” and i don´w want the user to be able to pass a certain transform.position.x.

What is the best way to achieve this? I could make a HUGE collider box to intercept the user. But that doesn´t seem good. A better way would to check if the user has passed x cord and then do something right?

How could i achieve this?

You could use the conditional check if(transform.position.x < xLimit) as suggested, or clamp the values (straight from the docs) :

transform.position.x = Mathf.Clamp(transform.position.x, -3.0, 3.0);

This makes sure the value is always between the min and max floats that are set in the command. More info here :

Well…you could add (if transform.position.x < xLimit) in the script before you get the player input, but personally I would use colliders.

Thx for your answers.

The problem i´m having is that if i do this my character will get stuck and recieve no input. I would still want my character to be able to move in the other direction.

The actual game problem is this. User starts with a road ahead of him. To the left is woods (with no collisions on the many…many trees). So i don´t want the user to go into the woods and find out i´m cheating a little bit for performence sake. So my plan was when the user enters the wood a text will be displayed and the user can´t go into the woods.