Short Lookahead Example

I was looking for documentation or examples on the forum covering how to have a camera smoothly look ahead of the player-controlled character on a platformer in GDevelop. I was kind of shocked there was not much I could find. I figured I would post my solution in case others were looking for the same.

There are a number of examples and solutions for a camera following with a delay including the wonderful SmoothCamera behavior. It would be great to have a lookahead option added to that existing behavior. Maybe it’s technically possible to configure lookahead using the existing behavior, but I could not find an easy way to do so.

In certain cases, the delayed camera scrolling can be frankly a frustrating game design decision. Sure, it adds a smooth look and feel, but from a gameplay element the player is now seeing LESS of the area in which they are moving towards and MORE of the area they are coming from which can be counter intuitive. I was inspired to update my existing snapped camera with a smooth camera lookahead after watching a recent Game Maker’s Toolkit video on ‘How to Make a Good 2D Camera’. Depending on the game it can be an excellent touch.

Full disclosure - I have been using GDevelop off and on for about a year, but I am not expert. There may be a better way to do this. I just think it useful to at least get the conversation started. That’s what a great community is all about, right?

Another quick heads up. The game I am making only has movement on the X axis. As such, I have not applied this logic to movement on the Y axis.

Before I breakdown my method, here is the end result:
Screen-Recording-2023-09-24-at-1 (1)

Here is my Event sheet:

A lot of complexity has been added due to the parallax effect I am going for requiring multiple layers to follow the player at different speeds. Additionally, the logic of this example game has interactable objects and buildings divided into different layers hence why some layers have the same action and function applied. If you are using a single layer and not looking to parallax, this process is less complicated.

Let’s breakdown what is going on.

  • At Beginning of the scene: This event aligns the camera center for every layer on the player at the beginning of the scene. In my case I want the player to begin centered on the screen until a direction is selected.

  • The variable Move_Left of Player >= 1: I have movement in this game determined by a variable as the player has several staggered moving speeds. This is why I have the movement variable as a number rather than a boolean. The important part here is that you need to condition this event on movement in a specific direction. There are many ways to accomplish this. In this case, if the player is moving in the left direction then the camera moves to follow the player + 25 using the lerp function. Adjust the + total to change the camera lead. For newbies: Here’s a good overview of what lerp does. In a sub condition, I have all of my parallaxed layers in an event group. This is strictly for visual organization and has no functional purpose. Do take note where I added the multiplier for the parallax on each layer. Ex: lerp(CameraCenterX()+25,Player.X()*.75,0.05). There might be a better way to approach this, but it worked well for my purposes.

  • The variable Move_Right of Player >= 1: This event has the exact same logic as Move_Left, but applied to right movement instead. As such, the camera position needs to be subtracted rathed than added on the X axis to look in the direction the player is now moving towards. Differentiating between movement directions is essential as the camera needs to predict where it is going to be moving. That is a little different than reacting to a player’s movement that has already taken place which is essentially what the SmoothCamera does.

If you are working on a game with Y movement you should me able to take the same approach I have for the X direction. I have not tested that myself so results may vary. Again, there may very well be an easier or more robust way to get the Lookahead camera feel. If so, please elaborate as I am always open to suggestions to learn better ways of applying logic, and it may help others looking up resources on this topic as I was earlier!