Weld joints

I would like to rigidly attach two physics bodies. In the API under physics joints, the weld joint contains the following text

“…if you want to rigidly bond multiple shapes together, you may want to specify them as multiple body elements within a single complex body, rather than using weld joints.”

Can someone explain to me what this means, or point me to an explanation?

Thanks! [import]uid: 102017 topic_id: 18425 reply_id: 318425[/import]

Hey chaiHu,

Take a look here, this has a good amount of information on complex bodies; http://developer.anscamobile.com/content/game-edition-physics-bodies#Complex_body_construction

Peach :slight_smile: [import]uid: 52491 topic_id: 18425 reply_id: 70723[/import]

This is very helpful, thanks!

Is there a way to name different parts of the physics shape, or set them up some way so that the various aspects of the shape “listen” for collisions differently?

In the provided car example, for instance, say I want an event to happen when something collides with the bumper or hood but not necessarily with the wheels. Is there a way to do this?
[import]uid: 102017 topic_id: 18425 reply_id: 70876[/import]

Hey there,

Check this out; http://developer.anscamobile.com/content/game-edition-collision-detection

You’d use a Runtime listener for collisions and then see which element was hit and respond accordingly.

Peach :slight_smile: [import]uid: 52491 topic_id: 18425 reply_id: 70931[/import]

This has been very useful, thanks.

I now have my complex physic object set up, it has two elements.

I cannot figure out how to get the terminal to return the value of the physics body, however, and so I have no idea how to differentiate the collision. I have tried (verbatim) the event.element1 (etc) with no results, and then I have tried tinkering with everything I could think of but I am just coming up stuck.

Suggestions?

[import]uid: 102017 topic_id: 18425 reply_id: 71328[/import]

This is something I quickly threw together using bits and pieces (including the example car shape), it isn’t pretty but it prints both element numbers from the collision - hopefully it will help :slight_smile:

[lua]-- Set up physics
require ( “physics” )
physics.start()
physics.setGravity( 0, 5 )
physics.setDrawMode ( “hybrid” )

local car = display.newRect( 100, 100, 60, 40 )
roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
hoodShape = { 0,-35, 37,30, -37,30 }
trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }

physics.addBody( car, “dynamic”,
{ density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
{ density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
{ density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)

local ground = display.newRect( 0, 470, 320, 10 )
physics.addBody(ground, “static”)
ground:addEventListener(“collision”, ground)

function onCollision (event)
if ( event.phase == “began” ) then

print( event.element1 … ": collision began with " … event.element2 )

elseif ( event.phase == “ended” ) then

print( event.element1 … ": collision ended with " … event.element2 )

end
end

Runtime:addEventListener(“collision”, onCollision)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 18425 reply_id: 71345[/import]

I was so close.

I am very grateful for your help.

:slight_smile: [import]uid: 102017 topic_id: 18425 reply_id: 71348[/import]

Not a problem!

Peach :slight_smile: [import]uid: 52491 topic_id: 18425 reply_id: 71369[/import]