As the title suggests, I'm looking for a way to clamp the position of my camera so it never leaves the bounds of the tile map. At present, the game follows around an avatar but when the avatar reaches the edges of the map obviously you can see off the side of the tilemap.
It's because of a lack of understanding over everything I'm having some issues of this. Through trial and error I worked out that to get the current tile my avatar is occupying I had to do:
int tileX = (int) (pos.x/2.5);
int tileY = (int) (pos.y/2.5);
This works ok, I'd be happier if I knew why I divided by 2.5 to get the current tileX and tileY. My tile size in pixels is 80 x 80, the cameras orthographic size is 10, zoom factor 1. I can't quite figure out from those numbers where the 2.5 comes from, but if I manually move my avatar to tile 64x64 and observe its X,Y position, I divide that number by 2.5 to get to 64,64
With that in mind, I started trying to clamp the camera to the bounds of the tilemap with:
camPos.x = Mathf.Clamp(camPos.x, 0.0f+(Screen.width/2*(1/this.globalCamera.orthographicSize)*(1/2.5f)), 2.5f*(this.explorer.tileMap.width-1) );
camPos.y = Mathf.Clamp(camPos.y, 0.0f+(Screen.height/2*(1/this.globalCamera.orthographicSize)*(1/2.5f)), 2.5f*(this.explorer.tileMap.height-1) );
(trying to restrict from going too far left, too far down to start off with). Any advice anyone could offer would be greatly appreciated!