Box2d locks the world while it dispatches events BEGIN_CONTACT, END_CONTACT, PRE_SOLVE and POST_SOLVE. And if the world is locked, these functions give assertion:
For your case, the solution is to create your joint outside of these events. (For example, you can set a flag and check this flag on ENTER_FRAME and if it's true create your joint)
r1 =50--radius of first body
r2 =94--radius of second bodylocalfunction onEnterFrame()
world:step(1/60, 8, 3)local x1,y1 = actors[1].body:getPosition()local x2,y2 = barriers[1].body:getPosition()local length =math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))print(length)if(length <(r1+ r2 + 20)and length >(r1+ r2))and weldJoint ==nilthen
jd = b2.createWeldJointDef(barriers[1].body, actors[1].body, barriers[1].body:getPosition(), actors[1].body:getPosition())
weldJoint = world:createJoint(jd)endend
But if FPS drop, one frame when length value will be higher than (r1+ r2 + 20), next frame - after some seconds, then we could lost value when length < (r1+ r2 + 20).
Comments
You need to create weld joint to stick them together.
Dynamic Object - actors[1].body
Creation weld joint on collision enter:
Expression IsLocked == false
When I use this code "onButtonPress" - than it works, else - fatal error..
Works not so well! help to find my error
Box2d locks the world while it dispatches events BEGIN_CONTACT, END_CONTACT, PRE_SOLVE and POST_SOLVE. And if the world is locked, these functions give assertion:
b2.World:createBody
b2.World:destroyBody
b2.World:createJoint
b2.World:destroyJoint
b2.Body:createFixture
b2.Body:destroyFixture
b2.Body:setActive
b2.Body:setPosition
For your case, the solution is to create your joint outside of these events. (For example, you can set a flag and check this flag on ENTER_FRAME and if it's true create your joint)
I mean set a flag on onBeginContact function and test this flag on onEnterFrame, if true create your weld joint.