How Make Camera Follow player within Bounds

Hi there guys,

i am completely new to Game making and programming… can u guys tell me how to make camera follow my player but the camera should remain inside the scene bounds?

pls don’t laugh :frowning:

1 Like

going to jump right back on Gdevelop to try it… thanks !!

1 Like

So I had a similar problem but only on the x-axis, but this method should be applicable for both. If your level is not a simple box then this will get more complicated but I think the basic principle should remain.

You need two separate events, one for both x and y axes.
For the x-axis.
Determine what half your game window width is. Subtract this from the total width of your scene.
In an event set two conditions

the X position of your object is > windowWidth/2
the X position of your object is > totalsceneWidth - windowWidth/2

The action will be

Do = Object.X() to X position of camera

So for example, my window width is 512, and my scene width is 1024, so my conditions look like this.

The X position of Object is >256
The X position of Object is >768

This should also work for the y-axis, but obviously with different values.

Hope this helps.

edit: Just realised that the first condition assumes your scene starts at an x-coordinate of 0. If it’s less than that, the first condition should be the leftmost point of your scene minus half the game screen width. So if my game scene actually started at -400, then I would have to add 256 to that. Hope that makes sense!


You can use the “Center the camera on an object within limits” action.
Assuming that the area is a rectangle, enter the coordinates of the top left and the bottom right corner of the rectangle.


Oh wow I didn’t even notice that action. That seems a lot better and more useful.

1 Like

where you can find the action?

1 Like

please show me how to find this action called center the camera on an object within limits

Search it up on the events sheet, specifically the actions column.