0
\$\begingroup\$

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?

\$\endgroup\$
11
  • \$\begingroup\$ 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? \$\endgroup\$
    – Zibelas
    May 3 at 17:53
  • \$\begingroup\$ Yeah, that's exactly what I want for my camera \$\endgroup\$
    – Arian_ki
    May 3 at 19:09
  • \$\begingroup\$ Is the tilemap fixed or are you generating it dynamically? \$\endgroup\$
    – Zibelas
    May 3 at 19:59
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Nikaas
    May 4 at 9:39
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    May 4 at 14:56

0

You must log in to answer this question.

Browse other questions tagged .