How to follow the player (or an object) with the camera?
Following a character (also called an object) with a camera is a key aspect of video game design that creates an immersive experience for players. This article includes instructions for implementing this functionality either with a simple extension like Smooth Camera or a set of actions on the Event Sheet.
Tip
GDevelop assigns a single camera per layer. It is recomended to start by placing the main objects o the "Base Layer", and add other layers after.
Follow an object (character) smoothly
Add the Smooth Camera behavior to the object that will be followed. The extension's parameters such as "catch up" and "speed" can be modified to personalize the smoothness of the camera.
Tip
Learn how to install new extensions by following a step-by-step guide.
Keep a character at the exact center of the camera
To configure the camera to center on an object, go to the event sheet and add an Action (no need to set a Condition) called "Center the camera on an object".
Select the object that will be followed by the camera and make sure that the layer where the object is placed is selected.
The Action should look like this:
Tip
To get closer to the character with the camera (zoom-in), use the action Move camera closer.
Follow an object with several cameras
Games can contain a lot of objects. Using several layers is a way to keep a project organized, but also to manage camera movements. All layers (except for UI layers) should likely be moved the same way when a character is followed. Read more on how cameras and layers work.
To follow a single object with different layers (each layer has a single camera), install the Copy camera settings extension. It allows to copy the main camera's position to a secondary camera.
Make a custom camera following (advanced)
To add camera inertia and a smoother transition watch this video tutorial to learn how to use the Camera Center positions on the X and Y axis, along with lerp
expressions and formulas.
You might be interested in:
- How to keep UI objects on screen.