# How To calculate camera boundaries

Is it possible to calculate the exact camera bounds? By this I mean the white lines that represent the camera area e.g the lines in the picture:

I'm using Camera.main.screenToWolrdCoordinates to convert screen coordinates to world coordinates because I want to position the player exactly on that white line that the camera represents:

But when I calculate the boundaries using Camera.main.screenToWolrdCoordinates I get this:

The players legs are outside of that lower camera bound on y axis, it will also happen on x axis when I strict the players movement by using the value that I got from Camera.main.screenToWolrdCoordinates , I also have bouncing balls in my game that I want to strict by the same boundaries. So my question is how can I calculate camera bounds exactly by this I mean again these white lines that represent the camera view, I hope that my question is clear enought. Just to make it more clear, when I calculate the bounds using Camera.main.screenToWolrdCoordinates I just assign the Y value that I got from that calculation to the Y position of the player.

• And I should pass Screen.width and Screen.height as arguments to viewport to world point right? Mar 11, 2015 at 13:51
• Can you be more specific please because the answer you gave me is not helping. Mar 11, 2015 at 20:25
• Are you checking the position of your player who is in world space? If so then use world to viewport and obtain the sprites height by accessing it through the sprite renderer component. If you character is at viewport position x:1, y:0.5, z:0 then it will be against the right edge of the camera and in the middle along the y axis... Check this tutorial out, it should help you youtube.com/watch?v=mq4BlZLReKk Mar 11, 2015 at 22:00
• thank you for your answer, yes I am checking the position of the player in world space, the tutorial you gave me is useful but it still does not answer my question, I want when the game starts to position the player on the ground e.g that lower white line representing the camera and that's what I'm trying to calculate Mar 12, 2015 at 5:28

Getting the lower boundary of the Camera in world space is easy with this little extension method:

public static float LowerBound(this Camera parent)
{
return parent.transform.position.y - parent.orthographicSize;
}


I could give some more flexible methods, but this is simple and does exactly what you need.

• Hello thank you for your answer but when I use the method that you game me I get he same result as the last picture above, the players legs are below the white line that represents the camera.... Mar 12, 2015 at 5:06
• @FahirM Is the player's transform centered at his feet? The transform might be at the right position, but the player's sprite and collider are offset somehow. Mar 12, 2015 at 6:36
• no its not, I did not modify the transform center so I think its positioned at center. Mar 12, 2015 at 6:59
• @FahirM There's your problem. Either you need to center the transform at the bottom of the player, or offset the player's position accordingly. Mar 12, 2015 at 7:00
• Try doing the same with an empty GameObject and see where the handles end up. I suspect Pachow is right. Also make sure you are setting the world coordinates and on the correct game object, not a parent. Mar 12, 2015 at 10:28