Constant player movement and camera follow

So I got both of these working but I would kinda like to ask a few questions about the whole thing.

First off let me explain my game. My guy will never go above the screen height, it’s just a long width map. There will only be a single touch key that makes the character go Up, and on release he falls down. My question is what is the best way to implement my guy to constantly move right? I know a few ways to easily implement this but which way would be the best or ‘proper’ way so I dont have to hack code later on, or at least much less? I will have objects he has to dodge that have collision but as I understand I can just make them static so I wont have problems with gravity. So just setting gravity on the x to a value the best way? or setLinearVelocity for the player on the x axis only even better since it only affects him? Any info on this would be much appreciated, sorry for the newbie question, just wanted to hear a more experienced opinion so I dont run into too much trouble later on if possible.

My second question is about the camera.
Heres my camera.lua

module(..., package.seeall)  
local camera = display.newGroup()  
return camera  

and heres my code

local camera = require "camera"  
camera:insert(background)  
camera:insert(ground)  
camera:insert(character)  
local function moveCamera(event)  
 if character.x \> 10 then  
 camera.x = -character.x + 10  
 end  
end  
Runtime:addEventListener( "enterFrame", moveCamera )  

this works fine just like i want it too, the player is always on the left side and the camera is following him around. my question is, is this perfectly fine to do the camera? can it really be that simple? lol. and secondly i learned that i have to set the “camera:insert(background)” for everything on my map pretty much. how come? If i end up having 20+ objects on each level I’d prefer not having to add every single one of them. I just dont understand why I have to add everything else besides the character, since its the character its following? Sorry again for the newbie question.

Thanks a lot for reading and thanks in advance for any help, it’s much appreciated. [import]uid: 77199 topic_id: 23157 reply_id: 323157[/import]

I’m not an expert but what you are looking for sound a lot like this tutorial. It explains how to generate an endless runner game, which sounds like what you are looking for. Hope it helps! [import]uid: 135394 topic_id: 23157 reply_id: 103089[/import]

Woo brings back memories, my first project. For those interested how to do something like this, it goes something like this:

local physics = require "physics"  
physics.start()  
physics.setDrawMode ( "hybrid" )  
physics.setGravity( 0, 0 )  
local character = display.newCircle( 50, 150, 20 )  
physics.addBody( character, "dynamic", { radius = 20, isSensor = true } )  
character.myName = "character"  
  
local function flying( event )  
 if event.phase == "began" then  
 character:setLinearVelocity( 0, -150 )  
 end  
 if event.phase == "ended" then  
 character:setLinearVelocity( 0, 150 )  
 end  
end  
Runtime:addEventListener( "touch", flying )  

[import]uid: 77199 topic_id: 23157 reply_id: 103094[/import]