Camera not following Player


I’m obviously missing something - probably very obvious, but for some reason when I set the Camera to centre to the Player (to follow the Player), the camera doesn’t move with him at all.

I’ve checked out the demo Platformer template and also a couple of tutorials on the camera following the Player, all simple stuff from what I can see.

I have a Player sprite with animations and also a PlayerHitBox (for better collisions) behind the Player. Selecting either of these for the Camera to follow doesn’t move the Camera as the Player moves.

Have you tried changing the X and Y position of the camera manually to those of the object you want it to be centered on?

You have to set the camera to the layer of your PlayerHitBox.

I don’t see your playerhitbox object on the scene in your screenshot.


Centering the camera to the Player or the Player’s HotBox using “Center the camera on an object withing limits”, “Camera center X postion” - none work.

I have tried testing all my layers, I have placed the Player and it’s HotBox in a Player layer and also used that as the Layer option inside the Camaera Position/target. I have also tried all my available layers to debug.

When selecting the Player layer, the Player disappears - camera does not move.
When testing each layer in turn, the objects within them are moved, but not the camera. The camera never moves or updates.

Wait, to clarify:
How many layers are you using in the game for actual visible units and logic?

Each layer has a unique camera, it’s very likely your camera is moving but if you are using multiple layers, you’re not seeing everything else move because their cameras are separate and aren’t moving. (you cannot target all cameras with a single event. You will need a camera action for each layer)

Please see my screenshot for my layers

Yes, I saw your screenshot, but how many of those layers are for actual visible units/logical items?

All of them?

If so, you need an event action for each one of those layers.

The only thing that isn’t visible is the Collision Layer for the Tiles.

So I duplicate the exact same Action for each layer recentering the Camera each time? Won’t Gdevelop get confused with all the different layers it has to re-centre too, or is this normal?

Nope, that’s normal. As mentioned, each action only impacts a single layer, and the layers do not care about each other. You will likely want to center your collision layer as well.

This is relatively normal for most game engines, otherwise you would have to constantly be moving your GUI objects or have to figure out super complex movement math for parallax backgrounds and such.

With a unique camera for each layer, if you’re doing a parallax background you can just say “Center the X position of this Camera (“Background1”): Set to CameraX(“baselayernamehere”,0)*0.5” and it’ll follow the normal camera but at half speed.

Note: The “camera number” is a holdover for compatibility purposes from prior versions of GDevelop. There is only 1 camera per layer, so that number should always be 0.

So you mean like this…

This is still a little confusing, as when set, the Player disappears from view.

Can you show your scene editor again, and click on your player? I need to see their properties to understand more.

In Construct there is a ‘Scroll-To’ behaviour, the only thing required is a reference to the Player, the camera just tracks the Player.

In Unity similarly, the camera can attached to the Player game object as a child and just copies the position of the Player as he moves. Alternatively you can code the camera to follow the Player. But the camera doesn’t need to know about any other objects.

I don’t understanding why GDevelop needs to work with the other layers, other than the Players position/location.

I’m not that familiar with GDevelop’s ways yet - shame there is no detail about this on the wiki.

Most of what is being discussed here is in most of the platformer and other tutorials (and examples in the engine)

And in Unity, attaching the camera to the player only impacts the layer the player is on (unless something has changed since the releases I messed with mid-2021), much like GDevelop. (Side Edit: Note that most people doing 2D in Unity tend to put everything on one layer in the first place and then use Z-depth for everything else in their conditional logic. Which you can also do in GDevelop)

Again, I’m still not seeing your player hitbox object on the scene. Can you select that and show a screenshot of it’s properties?

Edit: Also, your events aren’t set up right


You’re using “PlayerHitboxPlayerHitbox.X()” which isn’t a valid object name, and therefore not a valid expression. I’m guessing you want PlayerHitBox.X(), so this probably got partially autocompleted twice then copied over?

You might be able to resolve your issue by correcting your expression used. That said, I’m still not seeing the object on the scene at all, so fixing the expression may still only get you 0,0 for your position.

I didn’t see the extra PlayerHitBox in the action, I don’t recall adding it - it must have happened recently, but I’ve set it how it should be now and the camera is now working thanks.

In Unity, most people do put things in seperate layers and controll the z order/sorting layers, whether 2D or 3D. It’s also encouraged in Constrcut too. However I’m not here to critise your knowledge :wink:

The method to get things working is fine, but it isn’t obvious I’m sure for most new users. I hope other’s find the post useful.


1 Like

No worries! I’m glad it worked.

For reference I haven’t messed with Unity 2D much since they made Unity Learn free, but the above is how their Unity2D tutorials recommended being set up. I definitely could be out of date, and I don’t take anything you posted as a criticism, just a conversation.

As an optimization item, I’d still recommend you look at my example above. Decide what your “primary” camera layer is, then base your others off of that.

E.g. If your primary camera is the “player” layer, then for your other events, instead of using PlayerHitBox.X(), use the “Center X of Camera” expression (CameraX()), in this way: CameraX(“Player”,0).

That way you don’t have to risk doing a bunch of adjustments on the other layers unless needed. It can also be helpful if you ever change your main player’s object, or if you want to change the camera over to a cutscene object/fixed camera view for some reason.

1 Like

I’ll check out what you suggest tomorrow to see how it goes. Good to know a little more how GDevelop works.


1 Like