[lua]local function movePlayer()
motionx = 0 – Variable used to move character along x axis
speed = 5 – Set Walking Speed
local function moveLeft(event)
if “began” == event.phase then
motionx = - speed
animation.xScale = -1
end
if “ended” == event.phase then
motionx = 0
end
end
local function moveRight(event)
if “began” == event.phase then
motionx = speed
animation.xScale = 1
end
if “ended” == event.phase then
motionx = 0
end
end
local function moveUp(event)
if “began” == event.phase and animation.canJump == 0 then
transition.to(animation, {time = 750, y = animation.y - 100})
end
end
function charCollide( self,event )
if ( event.selfElement == 2 and event.other.objType == “ground” ) then
if ( event.phase == “began” ) then
self.canJump = self.canJump+1
elseif ( event.phase == “ended” ) then
self.canJump = self.canJump-1
end
end
end
animation.collision = charCollide
animation:addEventListener(“collision”, animation)
local function moveguy(event)
–map.updateView()
animation:setLinearVelocity(motionx * 40, 0)
map.positionCamera(animation.x - _W / 15, animation.y)
animation.rotation = 0
end
Runtime:addEventListener(“enterFrame”, moveguy)
leftButton:addEventListener(“touch”, moveLeft)
rightButton:addEventListener(“touch”, moveRight)
jumpButton:addEventListener(“touch”, moveUp)
end
movePlayer()[/lua]
I am just wanting to use physics so that they work in my project. Etc, Box2D physics are somehow buggy when I use them or I am not good with using them?