pivot question please help ! stuck for 3 days

i want to make a pancake like this (https://www.youtube.com/watch?v=tk8pYBqUjZM

i trying to make it. I’m able to make rubbery like the pancake

i asked the developer. & he replied me this “The pancake is made of 6 elements in the corona(box2d) that are joined with pivot joints, limited from something like -15 to +15 degrees”

so i did the same took a pancake cut in six pieces and try to make it .but the problem is  when my pancake get to edge , pivots are visible, the pancake is not curved like i the game. i used these parameters (i’m using: -friction, bounce, density & setLimitRotation) anything else? plz plz plz help me. i’m stuck at this from 3 days

my code is below :

local centerX = display.contentCenterX

local centerY = display.contentCenterY

local _W = display.contentWidth

local _H = display.contentHeight

local physics = require(“physics”)

physics.start()

physics.setGravity(0,9.8)

display.setStatusBar( display.HiddenStatusBar )

– The final “true” parameter overrides Corona’s auto-scaling of large images

local background = display.newImage( “jungle_bkg.png”, centerX, centerY, true )

–pancake part1

local p1 = display.newImageRect( “p1.png”,22,15 )

p1.x = 155; p1.y = 150;

physics.addBody( p1, “dynamic”, { friction=0.5,density=0.6 } )

–pancake last part (part6)

local p6 = display.newImageRect( “p6.png”,22,15)

p6.x = 215; p6.y = 150;

physics.addBody( p6, “dynamic”, { friction=0.5 ,density=0.6} )

–platform

local platform =display.newImageRect(“pancake.png”,70,20)

platform.x =205;platform.y =300

physics.addBody( platform, “static”, { friction=1,bounce =0 } )

local board = {}

local joint = {}

  board[1] = display.newImageRect( “p2.png” ,22,15)

  board[1].x = 165;board[1].y = 150

  physics.addBody( board[1], { density=0.5 ,friction=0.3 })

  joint[1] = physics.newJoint( “pivot”, p1, board[1], 165, 150 )

  joint[1].isLimitEnabled = true

  joint[1]:setRotationLimits( -15, 15)

  ----------------------------------------------------

  --joint2

  board[2] = display.newImageRect( “p3.png” ,22,15)

  board[2].x = 175

  board[2].y = 150

  physics.addBody( board[2], { density=0.5, friction=0.3 } )

  joint[2] = physics.newJoint( “pivot”, board[1], board[2], 175, 150 )

  joint[2].isLimitEnabled = true

  joint[2]:setRotationLimits( -15, 15)

  ----------------------------------------------------

  --joint3

  board[3] = display.newImageRect( “p3.png” ,22,15)

  board[3].x = 185

  board[3].y = 150

  physics.addBody( board[3], { density=0.5, friction=0.3 } )

  joint[3] = physics.newJoint( “pivot”, board[2], board[3], 185, 150 )

  joint[3].isLimitEnabled = true

  joint[3]:setRotationLimits( -15, 15)

  --joint4----------------------------------------------------------------

  board[4] = display.newImageRect( “p3.png” ,20,15)

  board[4].x = 195

  board[4].y = 150

  physics.addBody( board[4], { density=0.5, friction=0.3 } )

  joint[4] = physics.newJoint( “pivot”,board[3], board[4], 195, 150 )

  joint[4].isLimitEnabled = true

  joint[4]:setRotationLimits( -15, 15)

  --joint5-----------------------------------------------------------------

  board[5] = display.newImageRect( “p5.png” ,22,15)

  board[5].x = 205

  board[5].y = 150

  physics.addBody( board[5], { density=0.5, friction=0.3} )

  joint[5] = physics.newJoint( “pivot”, board[4], board[5], 205, 150 )

  joint[5].isLimitEnabled = true

  joint[5]:setRotationLimits( -15, 15)

  --joint 6----------------------------last joint

  joint[6] = physics.newJoint( “pivot”, board[5], p6, 210, 150 )

  joint[6].isLimitEnabled = true

  joint[6]:setRotationLimits( -15, 15)


  local function pushPancake()

      p1:applyLinearImpulse(0, -8, p1.x-10, p1.y )

  end

  p1:addEventListener( “tap”, pushPancake )

Hi

You should play a little with the distances between one piece and the other and their size

look at this example:

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local physics = require("physics") physics.start() physics.setGravity(0,9.8) --physics.setDrawMode( "hybrid" ) --debug hybrid normal display.setStatusBar( display.HiddenStatusBar ) -- The final "true" parameter overrides Corona's auto-scaling of large images local background = display.newRect(centerX, centerY,1000,1000, true ) background:setFillColor( 0, 0, 1 ) local jLimit = 15 local dist = 14 local piece = {} for i = 1, 6 do local newP = display.newRoundedRect( 0, 0, 20, 15, 2 ) newP.x = 100+(i\*dist) newP.y = 250 physics.addBody( newP, "dynamic" ) piece[i] = newP if(i\>1)then local pivotJoint = physics.newJoint( "pivot", piece[i], piece[i-1], piece[i].x, piece[i].y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -jLimit, jLimit ) end end local platform =display.newRect(0,0,70,20) platform.x =160;platform.y =300 physics.addBody( platform, "static", { friction=1,bounce =0 } )

Try to change the size of the pieces is the distance between them if you want to improve the result.

also uses 

physics.setDrawMode( "hybrid" )

 to better test physics

I hope this helps!

@maximo97 : you are my hero, just one more help please, I’m a beginner so forgive me for these silly questions

ques 1: i have six pieces of the image so how do i make a table for that, all are different. For example : i have named part1 (pancake: p1.png)

part 2(p2.png) and so on till 6th part(p6.png)

  1. on ur given example i can see pivot joints, so how do i get rid of that like in that pancake game, plz solve this also 

  2. how can i get in touch with you if i even need help?

No problem :wink:

1.if I understand correctly you say this:

for i=1,6 do local newP = display.newImageRect(myGroup, "p"..i..".png", 20, 15) --etc end

2.Sorry. My fault:

local piece = {} local joints = {} for i = 1, 6 do local newP = display.newRoundedRect( 0, 0, 20, 15, 2 ) newP.x = 100+(i\*dist) newP.y = 250 physics.addBody( newP, "dynamic" ) piece[i] = newP if(i\>1)then local pivotJoint = physics.newJoint( "pivot", piece[i], piece[i-1], piece[i].x, piece[i].y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -jLimit, jLimit ) joints[#joints+1] = pivotJoint end end

To remove:

for i=#joints,1,-1 do display.remove(joints[i]) table.remove(joints,i) end

See documentation:https://docs.coronalabs.com/guide/physics/physicsJoints/index.html#createremove

3.Nobody knows everything if you have problems I think it’s better that you ask here. more opinions are always better :slight_smile:

i was saying that i can see jagged lines, how do i remove that below is  a picture of what i’m trying to say

https://pbs.twimg.com/media/DfYCYjXV4AE8cCJ.jpg:large

when i keep distance it acts like a pancake but it starts to show jagged lines like it has been made up of tiny pieces, And when i decrease distance ( to remove lines) cake becomes straight? any help, please?

 

Hi

You should play a little with the distances between one piece and the other and their size

look at this example:

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local physics = require("physics") physics.start() physics.setGravity(0,9.8) --physics.setDrawMode( "hybrid" ) --debug hybrid normal display.setStatusBar( display.HiddenStatusBar ) -- The final "true" parameter overrides Corona's auto-scaling of large images local background = display.newRect(centerX, centerY,1000,1000, true ) background:setFillColor( 0, 0, 1 ) local jLimit = 15 local dist = 14 local piece = {} for i = 1, 6 do local newP = display.newRoundedRect( 0, 0, 20, 15, 2 ) newP.x = 100+(i\*dist) newP.y = 250 physics.addBody( newP, "dynamic" ) piece[i] = newP if(i\>1)then local pivotJoint = physics.newJoint( "pivot", piece[i], piece[i-1], piece[i].x, piece[i].y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -jLimit, jLimit ) end end local platform =display.newRect(0,0,70,20) platform.x =160;platform.y =300 physics.addBody( platform, "static", { friction=1,bounce =0 } )

Try to change the size of the pieces is the distance between them if you want to improve the result.

also uses 

physics.setDrawMode( "hybrid" )

 to better test physics

I hope this helps!

@maximo97 : you are my hero, just one more help please, I’m a beginner so forgive me for these silly questions

ques 1: i have six pieces of the image so how do i make a table for that, all are different. For example : i have named part1 (pancake: p1.png)

part 2(p2.png) and so on till 6th part(p6.png)

  1. on ur given example i can see pivot joints, so how do i get rid of that like in that pancake game, plz solve this also 

  2. how can i get in touch with you if i even need help?

No problem :wink:

1.if I understand correctly you say this:

for i=1,6 do local newP = display.newImageRect(myGroup, "p"..i..".png", 20, 15) --etc end

2.Sorry. My fault:

local piece = {} local joints = {} for i = 1, 6 do local newP = display.newRoundedRect( 0, 0, 20, 15, 2 ) newP.x = 100+(i\*dist) newP.y = 250 physics.addBody( newP, "dynamic" ) piece[i] = newP if(i\>1)then local pivotJoint = physics.newJoint( "pivot", piece[i], piece[i-1], piece[i].x, piece[i].y ) pivotJoint.isLimitEnabled = true pivotJoint:setRotationLimits( -jLimit, jLimit ) joints[#joints+1] = pivotJoint end end

To remove:

for i=#joints,1,-1 do display.remove(joints[i]) table.remove(joints,i) end

See documentation:https://docs.coronalabs.com/guide/physics/physicsJoints/index.html#createremove

3.Nobody knows everything if you have problems I think it’s better that you ask here. more opinions are always better :slight_smile:

i was saying that i can see jagged lines, how do i remove that below is  a picture of what i’m trying to say

https://pbs.twimg.com/media/DfYCYjXV4AE8cCJ.jpg:large

when i keep distance it acts like a pancake but it starts to show jagged lines like it has been made up of tiny pieces, And when i decrease distance ( to remove lines) cake becomes straight? any help, please?