# Make camera move constantly upwards in box2d world

Im using libGdx to develop a 2d game, which has the following:

• The world moves in an upward direction by having a camera follow the player's y position.

• The user only controls player's x movement, the y is a constant speed.

What i want to do now is let the user control the players x and y movement and let the camera move constantly up without following the player.

What is the best way to do this?

This is what i tried:

in Render()

player.body.setTransform(fingerPosition.x, fingerPosition.y, player.body.getAngle());

box2dCamera.position.y = box2dCamera.position.y + cameraSpeed;
box2dCamera.update();
box2dSpriteBatch.setProjectionMatrix(box2dCamera.combined);


This worked but all my collisions stopped working with other box2d bodies. Do i need to update each body in my game with the recalculated camera some-how? How would I do this?

• Why use physics bodies to control something that does not interact with anything physically? Dec 12 '14 at 18:21
• The player does interact with other bodies, as stated in the question, the collisions stopped working when I tried to do this. @ClassicThunder Dec 13 '14 at 19:17
• I'm referring to the camera. Dec 14 '14 at 2:39

There is no need to update each body when modifying the camera. Bodies' positions stays the same when you move the camera around. batch.setProjectionMatrix(cam.combined); already offsets your batch to the right position. The problem must result of this line :
 player.body.setTransform(fingerPosition.x, fingerPosition.y, player.body.getAngle());

Assuming you are rendering after this line of code and updating your world before, your player will always be positioned to fingerPosition, since the world has not been updated between this and rendering.