complex bodies get stuck inside each other

we're having trouble with complex bodies getting stuck inside each other when spawning in a similar position, or being dragged over each other
http://developer.anscamobile.com/forum/2010/11/19/complex-shapes-layering-over-top-one-another

this may relate to the topics here.. although i see no specific solutions. setting a groupIndex collision filter doesnt seem to help
http://www.box2d.org/forum/viewtopic.php?f=8&t=47
http://www.box2d.org/forum/viewtopic.php?f=3&t=1054&start=0

In an effort to try and find a temporary workaround I've also tried overlapping the polys a bit to see if this helps, unfortunately this provided to help. The complex objects still layer.

Here is a great example (borrowing jmp909's code) of these items layering. Please note I've simplified the shapes for this example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
physics = require("physics")
gameUI = require("gameUI")
physics.start()
physics.setDrawMode("hybrid")
 
local function dragBody( event )
        gameUI.dragBody( event )
end
 
local floor = display.newRect(0,430,320,50)
floor:setFillColor(0,255,0)
physics.addBody(floor,"static", {density=1})
 
local defs = 
{
 
        {shape={-120, -60, -80, -60, -80, 60, -120, 60}},
        {shape={-80, -60, 80, -60, 80, -20, -80, -20}},
        {shape={80, -60, 120, -60, 120, 60, 80, 60}}
 
}
 
function dropBlock()
        
        -- create dummy display object
        local obj = display.newRect(0,0,150,70)
        obj:setFillColor(255,0,0)
        obj.alpha=0.2
        obj.x=50+math.random()*200
        obj.y=math.random()*480
        physics.addBody(obj, "dynamic",unpack(defs))
        
        obj:addEventListener("touch",dragBody)
        
end
 
local t = timer.performWithDelay(0,dropBlock,-1)
t._delay=1000

Your "unpacks(defs)" will add multiple "shape=" elements when only one is expected. Have you tried it by only defining one shape?

-Tom

I wasn't aware that you could define a complex shape using one one definition. Could you provide an example of how this is done?

Here is an example of how I am doing this within my application currently:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
shape = {
        {-80, 40, -80, -40, -28.25, 11.75, -40, 40},
        {-80, -40, 80, -40, 0, 0, -28.25, 11.75},
        {0, 0, 80, -40, 28.25, 11.75},
        {28.25, 11.75, 80, -40, 80, 40, 40, 40}
        }
                        
local blockMaterial = {}
 
for i = 1, #shapes do
                
        local currShape = shapes[i]
                
        blockMaterial[i] =      {
                                density = 1.0,
                                friction = 1.0,
                                bounce = 0.0,
                                shape = currShape
                                }
end
 
local block = display.newImage ( path, 0, 0, true )
        
physicsRef.addBody (block, unpack (blockMaterial))

Any updates???

Problem is still active? Any solutions?

views:1051 update:2011/10/11 22:13:38
corona forums © 2003-2011