Stop camera follow at certain point

Hi,

I am working on a grid based game where a player moves along a grid-like board. The board is a big larger than the display size of the screen, which makes it necessary to have the camera follow the main player. However, when the user reaches one of the sides of the board (top/bottom/left/right), much of the board is cut off due to the object always being centered.

While looking through the perspective library, I have not found any specific modules to make it so that the camera has max follow ranges. Is there any way to add a max value to the camera so once it reaches a certain point rather than centering the follow object on the screen, it goes a bit off center to retain other parts of the scene?

If you need any more clarification, please let me know (I understand it is a tad bit confusing to explain).

Thanks.

What you need is math.clamp.  This doesn’t exist as standard but you can use this

function math.clamp(value, low, high) &nbsp; &nbsp; &nbsp; if low and value \<= low then &nbsp; &nbsp; &nbsp; &nbsp; return low &nbsp; &nbsp; elseif high and value \>= high then &nbsp; &nbsp; &nbsp; &nbsp; return high &nbsp; &nbsp; end &nbsp; &nbsp; return value end 

Basically you set the bounds for the camera as low, ** high and then track the player x,y with value**.  This will ensure the camera never exceeds the bounds you set for it. Obviously call it for both x and y axis.

What you need is math.clamp.  This doesn’t exist as standard but you can use this

function math.clamp(value, low, high) &nbsp; &nbsp; &nbsp; if low and value \<= low then &nbsp; &nbsp; &nbsp; &nbsp; return low &nbsp; &nbsp; elseif high and value \>= high then &nbsp; &nbsp; &nbsp; &nbsp; return high &nbsp; &nbsp; end &nbsp; &nbsp; return value end 

Basically you set the bounds for the camera as low, ** high and then track the player x,y with value**.  This will ensure the camera never exceeds the bounds you set for it. Obviously call it for both x and y axis.