Center Camera on Object not working (Solved)

I tried this action like tutorials on the GDevelop site instructed, but the camera doesn’t follow the object (the grey rectangle on the screen).

I tried stating the layer, but nothing changed. I also tried it with and without the Beginning of Game condition. Nothing changed, either.

You’re telling it to only center the camera at the start of the scene. In other words, it’s only centering it for 1 frame.

You need to remove the condition.

I tried it with the condition removed. No changes. The camera still won’t follow the grey box.

Is the PlayerHitBox object on the Base layer?

Not in the images above, but when I put the object on the Base Layer, this is what I see. The grey rectangle is in the center of the game screen and I can’t move it like I could before.

It is moving, but the camera is centring on it, so it is displayed in the middle of the screen.

[edited, 'cos this is plainly wrong]
If you put it back on the other layer, and use that layer in your center camera action, you should see the other objects on the base layer moving

Not for me. It doesn’t move at all. The grey box has the Platformer Object behaviour. When I press the keys to move or jump, nothing happens. The background doesn’t change or anything.

Apologies, I wrote that incorrectly before. If you have all the objects on the base layer, then you should see them move.

The other objects weren’t on the Base Layer. I just moved them all to the base Layer with the grey rectangle and now they work.

I guess that solves the issue, but why is it that the camera actions only work when all the objects are on the Base Layer? I’m asking because I’d like to make my platformer with different layers

If you have the other objects on different layers, you’ll have to move the camera for each of those other layers too.

Imagine each layer as a separate sheet. These layers of sheets have a small frame over part of them. Anything within that frame is what gets displayed on screen. When you move the camera for a layer, it’s similar to just moving that layer.

And what is displayed or viewed in the frame changes as that layer moves around.

The other layers don’t move, so what they display in the frame doesn’t change.

When you centre the camera on an object on a layer, you are shifting the layer so that the object stays in the centre of the frame. Again, you are only moving that one layer, and not the others.

HTH

1 Like

Okay, so if I wanna do the Center Camera action for objects on other layers, what do I need to do?

You use a “Center camera on PlayerHitBox” action for each layer, and specify the layer in the layer paramter. It’ll just use the PlayerHitBox position as the camera position; the object doesn’t have to exist on the layer you are centring, it just uses that object’s co-ordinates for that layer’s camera.

2 Likes