Hello,
So I have some code that is working fine in some cases, but if I try to trigger it from a colision instead of from timer check or user interaction I get the infernal “ERROR: physics.removeBody() cannot be called when the world is locked and in the middle of number crunching,” error.
I tried adding delays of 5ms, 50ms and 500ms to the funciton call, but it still happens. The function is only being called once (adding a print statement to it shows me this to be true in the console).
I wouldn’t need to remove the body except I have to change the filters (bitmask) of the physics object mid-game so that it can move behind objects it was previously impacting and I haven’t found any way to change filters except when a physics object is created…?
Here are some code snippets:
--called from colision: function changeDepth (event) timer.performWithDelay(50, event.spriteA.changeDepth(event.spriteB.lhUserCustomInfo.depth),1) end --this is spriteA's changeDepth function: objt.changeDepth = function (newDepth) if newDepth == ("front") then objt.curFilter = objt.frontFilter elseif newDepth == ("back") then objt.curFilter = objt.backFilter changeDepth = timer.performWithDelay(500,objt.rebuild(),1) end --this is spriteA's rebuild function: objt.rebuild = function () --remove body fails: physics.removeBody(objt) --since the remove fails, I can't get this part to work either; presumably the same problem: --local redCollisionFilter = { categoryBits = 2, maskBits = 2 } --physics.addBody(objt, { density=objt.myWeight/2, friction=0.2, bounce=objt.myBounce, radius = objt.radiux+2, filter = redCollisionFilter}, --{ density=objt.myWeight/2, friction=0.2, bounce=objt.myBounce, radius = objt.radiux, filter = objt.curFilter}) end
Any ideas? Driving me crazy and this is clinch-critical for my project.
Thank you!