# Stop camera follow at certain point

**URL:** <https://forums.solar2d.com/t/stop-camera-follow-at-certain-point/343789>\
**Category:** Gymbyl Coding\
**Created:** [April 10, 2017, 5:05pm UTC](https://forums.solar2d.com/t/stop-camera-follow-at-certain-point/343789 "2017-04-10T17:05:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hi16](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/h/a5b964/32.png) [@hi16](https://forums.solar2d.com/u/hi16)\
**Post date:** [April 10, 2017, 5:05pm UTC](https://forums.solar2d.com/t/stop-camera-follow-at-certain-point/343789/1 "2017-04-10T17:05:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [April 10, 2017, 9:33pm UTC](https://forums.solar2d.com/t/stop-camera-follow-at-certain-point/343789/2 "2017-04-10T21:33:10Z")

</div>

What you need is math.clamp. &nbsp;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,&nbsp;** \*\* high **and then track the player x,y with** value\*\*. &nbsp;This will ensure the camera never exceeds the bounds you set for it. Obviously call it for both x and y axis.

---

<div class="post-metadata">

**Author:** ![anon63346430](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/6a8cbe/32.png) [@anon63346430](https://forums.solar2d.com/u/anon63346430)\
**Post date:** [April 10, 2017, 9:33pm UTC](https://forums.solar2d.com/t/stop-camera-follow-at-certain-point/343789/3 "2017-04-10T21:33:10Z")

</div>

What you need is math.clamp. &nbsp;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,&nbsp;** \*\* high **and then track the player x,y with** value\*\*. &nbsp;This will ensure the camera never exceeds the bounds you set for it. Obviously call it for both x and y axis.
