[Solved] Camera and layers problem

hello, I’m trying to centre camera on the players Y position with limits but the different layers are causing problems. the player and enemy layer cameras are working correctly but when the player moves up and down shoots bullets they are way off relative to the enemy? thanks.

layers


camera

player

Why are you centering the background layer camera on the player? Because the very next line you adjust the y position of the background layer camera. Should it be the player layer camera?

And on which layer are you creating the bullets? It defaults to the base layer, and if you have that I suspect that’s what’s happening. And if you don’t adjust the base layer camera, then it would explain the discrepancy.

thanks I added the second camera action because I want parallax scrolling for the background but I don’t know how to add that using the within limits action?

the bullets are created on the player layer but as you assumed this is the problem but if I change the bullets to the enemy layer they hit the enemy but are way off the player instead :confused:

Are they? I don’t see the change layer command when you create the bullets.

Also, where is the camera position change for the player layer?

under create object the layer is set to “player” and the bullets are visible when shooting?

camera position change for the player layer is in the first action centre of camera is on player layer relative to the background layer. disregard the second action and the last action is camera centred on enemy layer relative to the player layer?

Ah, as part of the create statement, gotcha.


No, that centres the background layer camera on the player, not the player layer camera.

But anyway, I think the problem is you changing the enemy layer camera only on the y axis, and not applying the same rule to the player layer.

Imagine 2 sheets of paper one on top of the other. Both papers have a dot at the same position, so when viewed from above they are in the same spot. The two papers move up and down together, and the dots remain in the same position. But, the top layer can move left and right, while the bottom one cannot. So any sideways movements and the two dots are no longer in the same position when you view them, but they are in the same position on their respective pieces of paper.

That’s effectively what you are doing my moving one camera in the Y axis only, and the other in any direction.

If you place the bullets on the enemy layer, they’ll be displayed correctly relative to the enemy. Not sure ow this will look though.

thanks for your reply. I think it is better to upload the gdevelop file including the assets so you can test it out. any help would be great I have been struggling to figure it out :frowning:

Sure, I’ll have a look at a little later on. Can you briefly explain what you’re hoping to achieve or expect to see in the game?

thanks, it plays how I want the only exception is the bullet position and collisions.

visual example when player is centre screen
playermid

player is top of screen
playertop

player is bottom of screen
playerbott

Sorted. Here’s what it looks like :

BulletHellHelp


The event changes to get this :


And the bullets are created on the enemy layer :

image

1 Like

thanks solved! I didn’t know about camera differences :sweat_smile: thanks again for your help.

I have a question is there a way to change the background layer speed with the action "centre camera on “player”? the only way I know is a second action “change position Y” and add *0.25 speed

events

Not that I’m aware of. Center camera within limits only takes an object, and not co-ordinates. So your two step method is the only way I can see for now.

I normally would use the CameraX()/y() expressions, pointed at your base layer’s camera. This way the parallaxing still works if you move the main camera separate from the player.

Other than that, I agree with MrMen. As far as I know those events are going to be the only way to do it.