# Camera boundaries

**URL:** <https://forum.defold.com/t/camera-boundaries/67685>\
**Category:** Questions\
**Created:** [March 2, 2021, 1:19pm UTC](https://forum.defold.com/t/camera-boundaries/67685 "2021-03-02T13:19:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimbo\_Evans](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jimbo_evans/32/21143_2.png) [@Jimbo\_Evans](https://forum.defold.com/u/Jimbo_Evans)\
**Post date:** [March 2, 2021, 1:19pm UTC](https://forum.defold.com/t/camera-boundaries/67685/1 "2021-03-02T13:19:31Z")

</div>

For my 2D platformer game I am using the camera function and I was wondering if there is a way to get the camera to not go above or below a certain height when it is following a game object. For example if the player falls off the map I want the player to fall down but the camera to not follow so the player can’t see under the map.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 2, 2021, 3:36pm UTC](https://forum.defold.com/t/camera-boundaries/67685/2 "2021-03-02T15:36:50Z")

</div>

I think the solution is to not attach the camera to the player game object and instead update the position of the camera to match the player position, but ignore y/vertical position.

---

<div class="post-metadata">

**Author:** ![Jimbo\_Evans](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jimbo_evans/32/21143_2.png) [@Jimbo\_Evans](https://forum.defold.com/u/Jimbo_Evans)\
**Post date:** [March 2, 2021, 3:37pm UTC](https://forum.defold.com/t/camera-boundaries/67685/3 "2021-03-02T15:37:49Z")

</div>

I want it to do the vertical position within a boundary but not go out of those is that possible?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 2, 2021, 3:42pm UTC](https://forum.defold.com/t/camera-boundaries/67685/4 "2021-03-02T15:42:49Z")

</div>

If you control the position of the camera every frame, with the camera on a separate game object then you’re in full control. Example:

```lua
-- camera.script

-- get player position
-- use this as the base of the camera position
local pos = go.get_position("player")

-- keep camera position within 0-1000
if pos.y < 0 then
	pos.y = 0
elseif pos.y > 1000 then
	pos.y = 1000
end

-- update camera position
go.set_position(pos)

```

---

<div class="post-metadata">

**Author:** ![Jimbo\_Evans](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jimbo_evans/32/21143_2.png) [@Jimbo\_Evans](https://forum.defold.com/u/Jimbo_Evans)\
**Post date:** [March 2, 2021, 3:52pm UTC](https://forum.defold.com/t/camera-boundaries/67685/5 "2021-03-02T15:52:35Z")

</div>

Thank you
