Problem with physics objects.

Hi all,

can someone help me and identify what is the problem with my game?

–First Platform

panel = display.newImage(“panel.png”)

panel:translate(-270, -242)

panel:scale( 0.5, 0.5)

physics.addBody( panel, “static”, { friction=0.3, shape=panelShape } )

–Second Platform

panel2 = display.newImage(“panel.png”)

panel2:translate(-150, -300)

panel2:scale( 0.5,0.5)

physics.addBody( panel2, “static”, { friction=0.3, shape=panelShape } )

–Third Platform

panel3 = display.newImage(“panel.png”)

panel3:translate(-250,-350)

panel3:scale(0.5,0.5)

physics.addBody( panel3, “static”, { friction=0.3, shape=panelShape } )

–Bubble

local bubbleGroup = display.newGroup()

bubble = display.newImage(“bubble.png”)

bubble:translate( -250, -400)

bubble:scale( 0.5, 0.5)

physics.addBody( bubble, { density=1.0, friction=0.3, bounce=0.3 } )

^^This is the code for my 3 platforms and the bubble. However, when I start the game up in the simulator the bubble doesn’t drop down as it should but instead flies to the side. Any help would be appreciated!

P.S, I have my physics engine activated and also my gravity settings set to physics.setGravity( 0, 9.8 )

I don’t think this is anything to do with your platforms. Can you post more code?

Remember, in physics there are the concepts of:

  • collision
  • response

The latter is what the body will do when it encounters another physics body.

In you example, you’ve created all of your physics bodies using the default collision mask (i.e. none specified == -1).  This means all the objects you created will ‘collide’ with each other.

Furthermore, box2d does NOT allow colliding objects to overlap (unless one is a sensor).  So, if you create one body in the same space as another body, the bodies will be pushed apart in a random direction.  Because the bubble is ‘dynamic’ and the other physics bodies are ‘static’, AND because you are making the bubble over an existing body, this pushing is occurring.

Put this code right after the  addBody for the bubble and It should show what I’m talking about as far as overlap:

physics.setDrawMode( "hybrid" ) physics.stop()

Hi, thanks for the reply.

I have tried this and the bubble just stays still.

Having looked at the code you sent me in PM, I think one of your objects is so big that the bubble is going sideways because it is colliding with another object (they overlap) which can’t move, so it pushes the bubble away to the nearest side.

I will say that I haven’t run the code, but it looks like you’re missing some function definitions. Also, you’re using a lot of scaling, which often throws the physics out. I would try using no scaling and just size your platform etc images to the right size before using them. Remember that any resolution issues are solved by Corona when you load the images (assuming you provide enough sizes.)

I don’t think this is anything to do with your platforms. Can you post more code?

Remember, in physics there are the concepts of:

  • collision
  • response

The latter is what the body will do when it encounters another physics body.

In you example, you’ve created all of your physics bodies using the default collision mask (i.e. none specified == -1).  This means all the objects you created will ‘collide’ with each other.

Furthermore, box2d does NOT allow colliding objects to overlap (unless one is a sensor).  So, if you create one body in the same space as another body, the bodies will be pushed apart in a random direction.  Because the bubble is ‘dynamic’ and the other physics bodies are ‘static’, AND because you are making the bubble over an existing body, this pushing is occurring.

Put this code right after the  addBody for the bubble and It should show what I’m talking about as far as overlap:

physics.setDrawMode( "hybrid" ) physics.stop()

Hi, thanks for the reply.

I have tried this and the bubble just stays still.

Having looked at the code you sent me in PM, I think one of your objects is so big that the bubble is going sideways because it is colliding with another object (they overlap) which can’t move, so it pushes the bubble away to the nearest side.

I will say that I haven’t run the code, but it looks like you’re missing some function definitions. Also, you’re using a lot of scaling, which often throws the physics out. I would try using no scaling and just size your platform etc images to the right size before using them. Remember that any resolution issues are solved by Corona when you load the images (assuming you provide enough sizes.)