Limit Player Movement in Unity

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:

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SRE@Xero: Managing Incidents Part I

Deploying to Laravel Forge & AWS

Part 5: Hello World in Programming Languages

Part 11: Free Markets and Speculation

solehead customer care number 6289687993//6289687993solehead customer care number…

Game Dev Journal Entry 1: Deciding on a Game Engine

Residual model from scratch with Tensorflow.js [Part 2]

would it make sense to name this more along the lines:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rusben Guzman

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.

More from Medium

Creating a material in Unity

What are “Render Pipelines” in Unity?

Quick tip — Enabling post-processing in Unity Universal Render Pipeline

Saving Data in Unity3D Using Files