Objects "deleting" wall instead of bouncing

I have some code to try and stop some objects leaving the screen. Currently I spawn a wall on the left hand side of the screen with bounce = 1 but gravityscale = 0.

    local leftwall = display.newRect(0,246,10,480)     leftwall:setFillColor(0.5)     physics.addBody(leftwall, {bounce=1, filter = {maskBits = 4, categoryBits = 2}})     leftwall.gravityScale = 0

Elsewhere I have code that spawns some objects.

flying = display.newImage("flyingfly.png", 12, 12)     splat = display.newImage("flysplat.png",12,12)       flygroup = display.newGroup()     flygroup:insert(flying, true)     flygroup:insert(splat, true)     splat.isVisible = false       physics.addBody(flygroup, {bounce = 1, density = 1, filter = {maskBits = 2, categoryBits = 4}})     flygroup.gravityScale = 0       flygroup:translate( halfW + math.random( -100, 100 ), halfH + math.random( -100, 100 ) )     flygroup:addEventListener( "touch", buttonListener )

The forum editor seems to be really buggy with Comodo Dragon, so I’ll have to double post:

What happens is when the fly touches the wall, the wall disappears and the fly doesn’t bounce.

EDIT: I was wrong, it’s not removing it, it’s MOVING it. It’s knocking the wall over. An anchor should fix that, right?

EDIT2: Nope, an anchor didn’t fix it.

You need to make the wall “static”. By default, all physics objects are dynamic unless expressly stated otherwise. Try this:

physics.addBody(leftwall, “static”,{bounce=1, filter = {maskBits = 4, categoryBits = 2}})

Works a treat, forgot to change the object type. Thanks.

The forum editor seems to be really buggy with Comodo Dragon, so I’ll have to double post:

What happens is when the fly touches the wall, the wall disappears and the fly doesn’t bounce.

EDIT: I was wrong, it’s not removing it, it’s MOVING it. It’s knocking the wall over. An anchor should fix that, right?

EDIT2: Nope, an anchor didn’t fix it.

You need to make the wall “static”. By default, all physics objects are dynamic unless expressly stated otherwise. Try this:

physics.addBody(leftwall, “static”,{bounce=1, filter = {maskBits = 4, categoryBits = 2}})

Works a treat, forgot to change the object type. Thanks.