I have a problem with physics and my platformer game.

I am making a platformer game but I have ran into a lot of problems. First of all, take a look at this:

https://www.youtube.com/watch?v=D28y06M5zd0&feature=youtu.be

What is that? Why it happens? How to prevent it?

As I said, I have ran into a lot of problems with the Box2D physics.

My second question is: How to create/use physics for a platformer game? For me they are pretty buggy but I want to use physics in a way like this:

https://www.youtube.com/watch?v=3av3nyaLtes

I do not find those physics buggy.

Look, I am not trying to make a MMO game like that but all I want to do is to use physics in a non-buggy way.

Thanks

I’m not sure what you’re showing as buggy?  Can you provide a better description?

Also what version of Corona SDK are you using?

Rob

In the video; when I moved right and jumped it just flew to right. Sometimes it even floats somewhere.

I am not very sure of the version (because I am on my mobile now) but I can download the latest build.

In the video; when I moved right and jumped it just flew to right. Sometimes it even floats somewhere.

I am not very sure of the version (because I am on my mobile now) but I can download the latest build.

I download the newest build of the Corona SDK, the bug still happens.

It doesn’t look like you’re using Physics to move your object. It looks like you’re clicking and dragging. Can you share the code you’re using to move the object and what your expectations are?

Rob

[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?

Just looking at your code you’re using physics for your X movement, but you’re using transitions for your Y movement. As you try to transition your object upwards, gravity is fighting to pull your object downward. You shouldn’t use non-physics ways to move objects that physics is trying to move.

Maybe you might want to use a linear impulse to do the jump and let gravity bring the object back down.

Rob

Did not work :frowning: here is the code:

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 print"moving right" motionx = speed animation.xScale = 1 end if "ended" == event.phase then print"movement to right stopped" motionx = 0 end end local function moveUp(event) print(animation.canJump) if "began" == event.phase and animation.canJump \> 0 then animation:applyLinearImpulse(0, -50, animation.x, animation.y) end end function charCollide( self,event ) print(self.canJump, event.selfElement, event.other.objType) 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) local animationHorizontalVelocity, animationVerticalVelocity = animation:getLinearVelocity() animation:setLinearVelocity(motionx \* 40, animationVerticalVelocity) 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()

Plz guys I need this fixed…

Can you produce another video with the physics movement in place?

Can you provide a more detailed description of the problem that’s visible in the video, perhaps recording your voice while making the video describing the problem will help!.

Look at a project like the Sticker Knight demo: https://marketplace.coronalabs.com/asset/sticker-knight-platformer and study how it’s handling moving objects will help.

One of the reasons you don’t have a solid answer yet is that we really don’t understand what you want it to do, what you are observing it doing. Just looking at the video as is, doesn’t really show what the problem is and what the expectations are.

Rob

I’m not sure what you’re showing as buggy?  Can you provide a better description?

Also what version of Corona SDK are you using?

Rob

In the video; when I moved right and jumped it just flew to right. Sometimes it even floats somewhere.

I am not very sure of the version (because I am on my mobile now) but I can download the latest build.

In the video; when I moved right and jumped it just flew to right. Sometimes it even floats somewhere.

I am not very sure of the version (because I am on my mobile now) but I can download the latest build.

I download the newest build of the Corona SDK, the bug still happens.

It doesn’t look like you’re using Physics to move your object. It looks like you’re clicking and dragging. Can you share the code you’re using to move the object and what your expectations are?

Rob

[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?

Just looking at your code you’re using physics for your X movement, but you’re using transitions for your Y movement. As you try to transition your object upwards, gravity is fighting to pull your object downward. You shouldn’t use non-physics ways to move objects that physics is trying to move.

Maybe you might want to use a linear impulse to do the jump and let gravity bring the object back down.

Rob

Did not work :frowning: here is the code:

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 print"moving right" motionx = speed animation.xScale = 1 end if "ended" == event.phase then print"movement to right stopped" motionx = 0 end end local function moveUp(event) print(animation.canJump) if "began" == event.phase and animation.canJump \> 0 then animation:applyLinearImpulse(0, -50, animation.x, animation.y) end end function charCollide( self,event ) print(self.canJump, event.selfElement, event.other.objType) 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) local animationHorizontalVelocity, animationVerticalVelocity = animation:getLinearVelocity() animation:setLinearVelocity(motionx \* 40, animationVerticalVelocity) 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()

Plz guys I need this fixed…