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
Learn more about layers and cameras and how to keep UI objects on screen.
Follow a character smoothly
Add the Smooth Camera behavior to the object (remember to install it first from the Extension catalog). The Smooth Camera's parameters such as "catch up" and "speed" can be modified to personalize the smoothness of the camera.
Tip
Make sure that the character, enemies and platforms on the project are placed on the "Base Layer" on the layer panel. If the issue persist, ask the community on the forum.
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 several objects together
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 does cameras and layers work.
To follow several objects at the same time, install the Copy camera settings extension. It allows to copy the camera's position to another camera, including the camera that follows the player.
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.