Using physics whit camera following the player

I’m creating a game where you have a player, he walks left and right, jumps, ducks and fires. He starts on to of a building and goes down using elevators. There are 30 floors until the ground, so obviously it is not possible to fit the whole level on a single screen.

So I move the scene accordingly to the players Y position.

local function moveCamera() if (player.y \> screenH/2) or (player.y \< screenH/2) then content.y = -player.y + screenH/2 end end Runtime:addEventListener("enterFrame", moveCamera)

To make it more clear what am I moving:

function scene:create(event) local sceneGroup = self.view -- all display objects must be inserted into group sceneGroup:insert(camera) sceneGroup:insert(content) sceneGroup:insert(score)

for i=0, #walls do

content:insert(walls[i])

end

content:insert(elevator)

content:insert(player)

The physics gets corrupted using this. At least the hybrid mode shows so. And when I try to create a bullet on player’s Y position, it is created where the hybrid overlay box shows he is, not where the actual sprite is.

My question is, is it possible to have camera following player (only on the Y axis) in a large environment and still have physics? In the docs you say that I shouldn’t move groups that contain physics objects. What should I move then?

what build of corona are you using. This should be fixed in 2017.3028 and later.

https://developer.coronalabs.com/release/2017/3028/

Man thanks a lot, that was really it. It’s weird, because I registered and downloaded the SDK about 10 days ago, so I expected to get the latest version… somehow I had build 2016.2992.

Downloaded the one from your link and it works!

Really thanks a lot!

If you download from the public build link, you’re getting the most recent version that was fully evaluated as public-ready.

Daily builds are always ahead of the public release, but have the low possibility of containing issues.  

However, I find them to be pretty solid.

Thus I always get daily buildswhen I update (once or twice a week): https://developer.coronalabs.com/downloads/daily-builds/

Ok thanks for the explanation.

In the end I found out, that it was not fault of the hybrid draw model, although it is good that it now fits the sprites (but the physics actually worked ok), but I thought it’s all wrong since the bullet that I created on the player’s Y position, spawned at different position than the player was. But It was my bad, since I forgot to add the bullet to the scene, so that was the actual problem I had. Just in case someone will run into this problem in the future.

what build of corona are you using. This should be fixed in 2017.3028 and later.

https://developer.coronalabs.com/release/2017/3028/

Man thanks a lot, that was really it. It’s weird, because I registered and downloaded the SDK about 10 days ago, so I expected to get the latest version… somehow I had build 2016.2992.

Downloaded the one from your link and it works!

Really thanks a lot!

If you download from the public build link, you’re getting the most recent version that was fully evaluated as public-ready.

Daily builds are always ahead of the public release, but have the low possibility of containing issues.  

However, I find them to be pretty solid.

Thus I always get daily buildswhen I update (once or twice a week): https://developer.coronalabs.com/downloads/daily-builds/

Ok thanks for the explanation.

In the end I found out, that it was not fault of the hybrid draw model, although it is good that it now fits the sprites (but the physics actually worked ok), but I thought it’s all wrong since the bullet that I created on the player’s Y position, spawned at different position than the player was. But It was my bad, since I forgot to add the bullet to the scene, so that was the actual problem I had. Just in case someone will run into this problem in the future.