Limit Player Movement in Unity

Rusben Guzman
2 min readMay 9, 2021

--

In this example we define the limits where the player can move in the game, in the image below you can see the player moving freely in the scene with any restriction:

We gonna create two different limits, the player only will be able to move between two values in the Y axis and for the horizontal movement if the player get out of the screen he gonna appear in the other side:

Let’s start with the vertical movement, for this I gonna use an if statement to check if the position in the Y axis is out of the limits and keep the same position in case the condition is true:

Ok now we check when the player reach one of the limits in the X axis we set multiply the X axis by -1 to make the player appear in the other side:

And that it’s, you have defined limits for your player movement:

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet