1
votes

I am making a game in Corona sdk where different balls bounce and stick to each other with a weld joint. When I reset the gameplay, all joints are destroyed, then all the balls are repositioned. Here is some of my code:

--stickJoints and balls are tables that contain all the weld joints and ball objects
resetTotal = function()
    for i=1,#stickJoints do
        stickJoints[i]:removeSelf()
        stickJoints[i]=nil
    end
    for i=1,20 do
        --this resets all balls and sets linear and angular velocity to 0
        resetP(balls[i],1000+(i-1)*400,5000,0)
    end
end

The problem is that as soon as I tap the reset button, the balls that were connected temporarily interact with each other. Any thoughts are helpful. Thanks!

1
Try physics.pause() before reset... - Krishna Raj Salim
Your last paragraph is not clear: what is symptom, what happens that should not happen, what does the momentary interaction result in. - Oliver
@Schollii Sorry, The balls will snap together as if the joint is not destroyed yet, but is then detroyed right after. When I pause the physics and set it to debug draw mode, the joint still exists after I reposition the balls, and is only destroys after physics starts again - Sam Hogan

1 Answers

1
votes

I think your best bet is either

  1. to use timer.performWithDelay to call a function that will reposition the balls after the physics has had a chance to break the constraint.
  2. Remove each ball from physics, and use a delayed function cal (see item 1) to re-add them after having been repositioned.