Question about moving physics object with a pic on it between containers

Hi there - I'm making a claw machine. I've created a bunch of plushies to go inside of it with the following code

let sprite = new Pic (plushies).pos(i*120,100, RIGHT, TOP);

let plushy = new Blob({
        points:simplifyPoints(outlineImage(new Bitmap(sprite)), 10), 
        color:red, 
        interactive:false 
    }).loc(sprite).sca(0.5);
    
sprite.addTo(plushy);
plushy.addPhysics({dynamic:true, bounciness:.5});
plushy.addTo(innerBounds)
physics.drag(plushy); //remove for final
physics.drag(sprite); //remove for final
plushyList.push(plushy)

For now, the plushies are draggable inside the claw machine, but I want to make them not interactable in the final project (so that the user has to rely on the claw to get them out).
But once the plushy lands in the output area, I want to make it so that once the user clicks the plushy, it moves to an outside 'layer' where it is not affected by the collision of the claw machine and can be freely tossed around. I tried to achieve this by changing the container that the plushy is on with the following.

innerBounds.on("pressup", (e)=>{
    let item = e.target
    if (item.hitTestRect(contactBar)) {
        zog("hit")
        innerBounds.removeChild(item)
        item.addTo(outside)
        zog(innerBounds)
        zog(outside)
    } 
})

This results in many problems. The first is that the plushy moves to the outer layer in two parts: once for the blob and once for the pic that is on the blob. You need to click on the plushy twice to get it out, and once it is out the two parts of it are desynced. Is there a way to get the whole plushy with both parts to move to the new container together? The second problem is that once the plushy moves to the outer layer, it increases in size and does not seem to be affected by physics. Could you please advise?

Thanks

Hi @meg - which container it is in will not matter - although any container that you put a physics object in must be positioned at 0,0 relative to the stage and not be scaled rotated or skewed.

Anyway, what you are looking for is the maskBits and categoryBits parameters. They affect which objects interact with which other objects. It is a little tricky but this is an example.

https://www.iforce2d.net/b2dtut/collision-filtering

1 Like