Hi!
I have been trying to implement compound shapes in Defold. I want to attach multiple shapes to a single kinematic collision object, so i can create non convex shapes, like an “L”.
The first implementation worked, when i created a separate go for every “block” instead of adding multiple shapes. The problem was that those blocks collided with blocks in the same shape. I filtered those collisions from lua, but they got reported from the engine so it generated a tons of useless contact point messages.
The collision object has a “dummy” 1x1x1 shape added from the editor. The runtime created shape appears on screen with physics debug. It moves with with the go.
The problem: the runtime created shape does not collide with anything. Only the dummy shape collides with the tilemap.
I made a new script which only adds a single collision shape at the center of the go, so i can eliminate every flaw that might be caused by the shape generation from the tile layer.
The create shape code:
local collision_url = Utils.get_fragment_url(msg.url(), C.FRAGMENT_HASHES.collision_obj)
local body = b2d.get_body(collision_url)
local box_data = {
type = b2d.shape.SHAPE_TYPE_BOX,
hx = C.HALF_TILE_SIZE,
hy = C.HALF_TILE_SIZE,
hz = C.HALF_TILE_SIZE,
center = vmath.vector3(0, 0, 0),
restitution = 0.5,
friction = 0.1
}
b2d.body.create_shape(body, box_data)
local shapes = b2d.body.get_shapes(body)
for i = 1, #shapes do
local s_id = shapes[i].shape_id
b2d.shape.enable_contact_events(s_id, true)
end
I added some logging to represent the shapes on the collision object:
DEBUG:SCRIPT: body world Box2D.b2world = 0x7fc78002d9e0
DEBUG:SCRIPT: -----------------------------
DEBUG:SCRIPT: before enable contact_events false
DEBUG:SCRIPT: after enable contact_events true
DEBUG:SCRIPT: shape,
{ --[[0x7fc78002dcb0]]
vertices = { --[[0x7fc78002def0]]
1 = vmath.vector3(-16, -16, 0),
2 = vmath.vector3(16, -16, 0),
3 = vmath.vector3(16, 16, 0),
4 = vmath.vector3(-16, 16, 0)
},
type = 3
}
DEBUG:SCRIPT: shape world Box2D.b2world = 0x7fc78002e410
DEBUG:SCRIPT: shape data,
{ --[[0x7fc78002d960]]
child_count = 1,
is_chain_segment = false,
restitution = 0.5,
friction = 0.10000000149012,
material = 0,
density = 1,
sensor = false,
type = 3,
shape_id = Box2D.b2shape = 0x7fc78002da20,
index = 1
}
DEBUG:SCRIPT: ------------------------------
DEBUG:SCRIPT: before enable contact_events true
DEBUG:SCRIPT: after enable contact_events true
DEBUG:SCRIPT: shape,
{ --[[0x7fc78002e540]]
vertices = { --[[0x7fc78002e5d0]]
1 = vmath.vector3(-0.5, -0.5, 0),
2 = vmath.vector3(0.5, -0.5, 0),
3 = vmath.vector3(0.5, 0.5, 0),
4 = vmath.vector3(-0.5, 0.5, 0)
},
type = 3
}
DEBUG:SCRIPT: shape world Box2D.b2world = 0x7fc78002e8c0
DEBUG:SCRIPT: shape data,
{ --[[0x7fc78002dbe0]]
child_count = 1,
is_chain_segment = false,
restitution = 0.5,
friction = 0.10000000149012,
material = 0,
density = 1,
sensor = false,
type = 3,
shape_id = Box2D.b2shape = 0x7fc78002dc60,
index = 2
}
DEBUG:SCRIPT: ------------------------------
In game with physics debugging:
The collision resolving code works (it works for other stuff in the game like the player). Based on the image, i think only the 1x1x1 dummy shape at the center of of the go collides with the tilemap.
Thanks for any help!


