Physics Engine Error or not ?

Hello, I am creating some boxes (which I read from the tutorials ) and a dragging event to move them freely on display just to test some stuff. The weird thing that is happening is: When I drag a box on to another one it does not act like it is a physics object it just gets over to other one and overlaps till I remove my finger.

Box spawn code, called with a timer  
  
local boxIndex = {}  
local function boxSpawn( event )  
 boxIndex = boxIndex + 1  
 boxTable[boxIndex] = display.newImageRect( "box.png", 64, 64 )  
 local xBox = math.random(0,150)  
 local yBox = math.random(0,150)  
 boxTable[boxIndex].x, boxTable[boxIndex].y = xBox, yBox   
  
  
  
  
boxTable[boxIndex]:setReferencePoint(display.TopLeftReferencePoint)  
  
 physics.addBody(boxTable[boxIndex], {density = 0.5, friction = 0.3, friction=0.1})  
 boxTable[boxIndex].id = "Box"..boxIndex  
 print(boxTable[boxIndex].id)  
  
 obj:insert(boxTable[boxIndex])  
  
 boxTable[boxIndex]:addEventListener("touch", onTouch)  
 print("New Box Spawned at:".. xBox ..":"..yBox)  
  
end  
  

And below is the dragging stuff:

  
local function onTouch( event )  
 local t = event.target  
 local phase = event.phase  
 local stage = display.getCurrentStage()  
  
  
 if "began" == phase then  
  
 stage:setFocus(t, event.id)   
 t.isFocus = true  
   
  
 t.x0 = event.x - t.x  
 t.y0 = event.y - t.y  
  
if not(t.x0 == 0) and not(t.y0 == 0) then  
 print("Over")   
else  
 print("Out")  
end   
  
 elseif t.isFocus then  
 if "moved" == phase then  
  
 t.x = event.x - t.x0  
 t.y = event.y - t.y0  
  
 --t.x = event.x - event.x % 32  
 --t.y = event.y - event.y % 32   
  
print( event.x - t.x0 % 32 .."-".. event.x - t.x0)  
 elseif "ended" == phase or "cancelled" == phase then  
 display.getCurrentStage():setFocus( t, nil )  
 t.isFocus = false  
  
 end  
 end  
  
 return true  
end  

Thanks [import]uid: 73033 topic_id: 24083 reply_id: 324083[/import]

This would depend on the body type of the box.

If you run some of the physics samples (the platform one is best) from the samplecode folder then you will see examples of this.

Peach :slight_smile: [import]uid: 52491 topic_id: 24083 reply_id: 97263[/import]

Yea saw that and tried it but isnt dynamic bodies have to collide with eachother no matter what.
I mean think it like real world, If I push a box towards another, it will not go inside of it for a few seconds and then magically come back.
[import]uid: 73033 topic_id: 24083 reply_id: 97277[/import]

That is true but it would help if you provided plug and play code so (or others) might run this.

Physics isn’t always perfect but we do have a few suggestions to try when this kind of thing comes up, including making sure the bodies have isSleepingAllowed set to false.

Also, see these APIs:
http://developer.anscamobile.com/reference/index/physicssetpositioniterations
http://developer.anscamobile.com/reference/index/physicssetvelocityiterations [import]uid: 52491 topic_id: 24083 reply_id: 97354[/import]