Hi all! I’m having some trouble, probably relating to a limited knowledge of math, limiting my camera’s position so that it doesn’t draw anything beyond the boundaries of the level.

Problem:

I am creating a 2.5D platformer. I have a Zone gameobject which contains various properties for a given area of a level. Each Zone has a Rect field which defines the gameplay limits of the Zone (xmin, xmax, ymin, ymax) outside which no gameplay or art will exist. The camera, which uses perspective projection, is situated at a variable z distance from the gameplay axis. I would like to limit the camera’s movement so that the visible area does not exceed xmin, xmax, ymin or ymax on the zero-z-axis.

I’m not great with math, unfortunately, but I thought I might be able to solve the problem by calculating the visible rectangle where z = zero, and then correcting position where that visible rectangle exceeds the boundary of the Zone… but I’m only guessing and I’ve had no luck anyway calculating that visible rectangle.

Perhaps there’s an easier way to solve this problem, with clever use of game objects or colliders? I’m really stumped on this one.