physics during a collision

Hi, I ran into the constraint of corona sdk, how to get around it?

local function onLocalCollision( self, event ) if ( event.phase == "began" ) then print( self.myName .. " collision began with " .. event.other.myName ) wall.myJoint = physics.newJoint( "weld", wall, cactus, wall.x, wall.y ) end end image.collision = onLocalCollision image:addEventListener( "collision", image )

ERROR: C:\Users\Mark\Documents\Corona Projects\CactusMen\main.lua:143: physics.newJoint() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event

The object must collide with the wall and “weld” to it. How to do this? I will be grateful for code examples

Put the physics.newJoint call inside a brief timer to allow the collision calculations to finish:

local function onLocalCollision( self, event ) if ( event.phase == "began" ) then print( self.myName .. " collision began with " .. event.other.myName ) timer.performWithDelay(10, function() wall.myJoint = physics.newJoint( "weld", wall, cactus, wall.x, wall.y ) end) end end image.collision = onLocalCollision image:addEventListener( "collision", image )

And welcome to the Corona forums!

Rob

Put the physics.newJoint call inside a brief timer to allow the collision calculations to finish:

local function onLocalCollision( self, event ) if ( event.phase == "began" ) then print( self.myName .. " collision began with " .. event.other.myName ) timer.performWithDelay(10, function() wall.myJoint = physics.newJoint( "weld", wall, cactus, wall.x, wall.y ) end) end end image.collision = onLocalCollision image:addEventListener( "collision", image )

And welcome to the Corona forums!

Rob