Making Multi-Element Bodies Only Register One Collision

Is there a way to make the individual pieces of a Multi-Element body act as one piece so that if another object hit both pieces of the same object at the same time it would only register one collision?  Or is there a way to figure out which pieces of the multi-element body the object collided with?

For example the player in the following code receives four collisions,  I need him to either only receive two collision one for first hitting the box and one for one it finally stops hitting the box.  Or I need to know which part of the element that the player initially hit.

I understand it doesn’t really make sense to have a box that’s a Multi-Element but this is just an example.

[lua]

physics = require( “physics” )

physics.setDrawMode( “debug” )

physics.start()

function contact()

    if player.conflicting == nil then

        player.conflicting = “yes”

    elseif player.conflicting == “yes” then

        player.conflicting = nil

    end

    print(player.conflicting)

    

end

box = display.newRect(50,50,50,50)

physics.addBody( box, “static”, 

    {shape={-100,-75, -0,-75, -0,75, -100,75}, isSensor=true},

    {shape={-0,-75, 100,-75, 100,75, 0,75}, isSensor=true}

    )

box.x=320

box.y=480

player = display.newCircle(50,50,25)

physics.addBody( player, “dynamic”, {radius = 25})

player.x=160

player.y=480

player:setLinearVelocity(200,0)

player.collision = contact

player:addEventListener(“collision”,player)

[/lua]

Hi @DCbball4life,

I wrote a tutorial a few months back on exactly this topic. Please read it and let me know if you have further questions.

http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

Have fun!

Brent Sorrentino

Hi @DCbball4life,

I wrote a tutorial a few months back on exactly this topic. Please read it and let me know if you have further questions.

http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/

Have fun!

Brent Sorrentino