Making Your Character Wrap on Screen

Jacob Jones
2 min readJun 22, 2021

--

While moving our character, we want them to go of screen and then appear on the other side!

To make this magic happen, we are going to use an if and else statement. First you need to find the dimensions of the camera box so we know what numbers you need to use. Go into Unity and click on your player in the inspector view. Now press play and look at the x transform when you move them left or right. See what the maximum and the minimum numbers are!

Once you know where you want your player to appear on the other side, we are ready to begin coding. Open your script with controls and lets begin our if statement under void update. We are going to type “if (transform.position.x >= your number here){”. This is telling the script, if the x position is greater than or equal to our number, then do this.

Now we need to tell it what to do if this is true, we want it to appear on the other side. So we are telling it, hey once you get to 11.3 on the x, I want you to go to -11.3 on the x. One thing we want to make sure though, is that it is also taking in consideration of the Y to avoid any bugs. Type, transform.position = new Vector3(your number, transform.position.y, 0);

After we get that knocked out, we need to do the opposite, so if x is less than or equal to our minimum, we want it to appear on the positive side of the x. This will be done using an else if statement.

This is all we need to make our character look like they are transitioning off screen to the other side!

--

--