[lua]function onCollision(event )
print(“collision”)
local function realCollisionHandler()
if(event.object1.x <0 and event.object1.y<0) then
event.object1:removeSelf()
event.object2:removeSelf()
print(“remove”)
else
print(event.object1.contentWidth)
print(event.object1.contentHeight)
print(event.object2.contentWidth)
print(event.object2.contentHeight)
local vx2, vy2 = event.object2:getLinearVelocity()
local vx1, vy1 = event.object1:getLinearVelocity()
local rock = display.newCircle((event.object1.x + event.object2.x)/2,(event.object1.y + event.object2.y)/2,(event.object1.contentHeight + event.object2.contentHeight)/3 )
physics.addBody(rock,“dynamic”,{friction = 0,bounce = 0})
rock:setLinearVelocity( (vx1+vx2)/2,(vy1+vy2)/2)
event.object1:removeSelf()
event.object2:removeSelf()
end
end
–physics.addBody(rock,“dynamic”,{friction = 0,bounce = 0})
timer.performWithDelay(1,realCollisionHandler,1)
–myGroup = nil
end[/lua]
My simulator will spawn random objects and they will merge when collide with each other. However, when more than 2 collisions happen at the same time, it will crash. Could some please give me a suggestion how to fix this?