PHYSICS HELP!!! - I'm not sure what is happening

I’m working with a student who wants to make a plinko game. My thought was to generate the pegs, put them in a group, and position the group. Interestingly, when I reposition the group to the center of the screen, the physics bodies (view in hybrid) appear to have moved, but the when the chip drops, it bounces off “invisible pegs” This is where the pegs were originally made before I moved the group. Any help is greatly appreciated as I have NO IDEA why this is happening!

display.setStatusBar( display.HiddenStatusBar )

– Screen Coordinates
centerX = display.contentCenterX
centerY = display.contentCenterY
screenLeft = display.screenOriginX
screenWidth = display.contentWidth - screenLeft * 2
screenRight = screenLeft + screenWidth
screenTop = display.screenOriginY
screenHeight = display.contentHeight - screenTop * 2
screenBottom = screenTop + screenHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight

local physics = require(“physics”)
physics.start()
physics.setDrawMode(“hybrid”)

local pegRadius = 10

local pegGroup = display.newGroup()
pegGroup.anchorChildren= true
pegGroup.x = centerX
pegGroup.y = centerY

local function generatePegs()

local x, y
local offset = 50

local peg

for row = 1,10 do

if row % 2 == 1 then
  for column = 1, 8 do
    x = 100 * column
    y = 100* row 
    peg = display.newCircle(x, y, 10)
    peg.name = "peg"
    physics.addBody(peg,"static", {bounce = .1,friction = .2,radius = 10})
    pegGroup:insert(peg)
    peg = nil
    print(x,y)
  end
else
  for column = 1, 7 do
    x = 100 * column+offset
    y = 100 * row 
    peg = display.newCircle(x, y, 10)
    peg.name = "peg"
    pegGroup:insert(peg)
    physics.addBody(peg,"static", {bounce = 0.1,friction = .2, radius = 10})
    peg = nil
    print(x,y)
  end
end

end
end

generatePegs()

local ball = display.newCircle(centerX, screenTop + 50, 35)
physics.addBody(ball, “dynamic”, {radius=35})

if you put the circle inside the group it will work fine I guess… but you need to reposition the ball

local ball = display.newCircle(470, 200, 35)
physics.addBody(ball, "dynamic", {bounce = 0.1,radius=35})
pegGroup:insert(ball)

Hey. I think your problem comes from translating the group. The physics engine recognizes the x, y location based off of the object and doesn’t consider the translation of the group. Whenever I am using group programing for a physics simulation, I don’t translate the group. Instead I add all the translations to the object.

Thanks for the feedback… I will give both the options a go THANKS for the help!!!

OK, so I tried simply inserted the ball in the display group and the problem was solved. I will also keep KyleLeighGames suggestion in the back of my head as it might more sense to things that way in certain situations! thanks again!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.