# Making sure the player and the camera are in the borders

What I need is a way to automatically create an invisible border around the current tilemap (tile map uses simple rectangular tiles)

The player character uses

rb.movePosition(transform.position + direction * speed


and direction comes from a custom joystick.

The camera (a pixel perfect camera, as the game is pixel art) is just simply set to be in the same position as the player.

What I want to do is to NOT let the player get out of the map and I don't want the camera to show the black parts around the map (places where nothing is placed), is there a good way to do this?

• Since you said the camera is at the same position as the player, how do you want it to be when the player walks to the border? Should the camera stay put and the player just walks to the border - so that the last tile just touches the border of the screen? May 3 at 17:53
• Yeah, that's exactly what I want for my camera May 3 at 19:09
• Is the tilemap fixed or are you generating it dynamically? May 3 at 19:59
• You may want to research unity's Cinemachine. It has "room" like capability that allows you to define an area that limits the camera view inside of it. May 4 at 9:39
• transform.position + direction * speed is a destination for where you want to be next frame / next physics step. Don't think so narrowly - it will block you from finding simple answers. May 4 at 14:56