Sensor to sensor collision, or how to achieve this?

Hi everyone.
This is gonna be long, apologies for that :slight_smile:

THE CONTEXT
I’m trying to create a level where some sprites are loaded from file definition in order to form some structures. The player can add more pieces by drag-and-drop from a toolbar and then hit a “start” button to start the physic simulation (sprites falling down, etc.).

In a sense, it’s similar to the “Bubble Ball” Corona game. HOWEVER there is a difference I need to implement: pieces the player place cannot be overlapping other objects. In Bubble Ball, the player could place a piece overlapping an element of the level (like a wall) and the piece would be pushed outside the wall only at level start.
What I what to achieve is to give some feedback while placing the piece: if it is overlapping a pre-existing piece or the level, the piece cannot be placed (let’s say it will be coloured in red) and the user should keep dragging in until it gets to a “valid” position.

THE PROBLEM:
I want the collision check for the placement of a new object to be performed before the simulation starts - i.e. before loose pieces starts falling down as per gravity. This can’t be done when the physic simulation is off because collisions won’t be fired. So this has to be done while the physic simulation is on, however I don’t want pieces to fall down or to bounce off each other (e.g. if pieces loaded from the level are overlapping).

FAILED APPROACHES:

  • Turn all sprites into sensors, so that they don’t interact with each other or gravity. Then delete them and recreate them as normal bodies when simulation starts. PROBLEM: sensor-to-sensor collisions not firing?

  • Turn all sprites into “kinematic”, so that they don’t fall down, and turn the piece I’m placing in a kinematic sensor. PROBLEM: kinematic-to-kinematic collisions not fireing? (and btw, shouldn’t overlapping kinematic bodies be pushed away? it’s not happening)

  • Turn all sprites into “static”, so that they don’t move or interact in any way. Have my placing piece to be a kinematic sensor. PROBLEM: static-to-sensor collisions not firing?

  • I tried placing dynamic objects in the scene. They do fire collisions when touching my kinematic sensor piece I’m dragging around. However they also fall down - move outside intersecting objects, that’s not what I want until the player press the “start” button"

  • Turn all sprites into static, and use a dinamic body as my placeable piece. PROBLEM: it will bounce off walls instead of just giving an “invalid position” feedback, it will not cross wall (let’s say I want to place it inside a box, it won’t be able to cross box walls).

  • Turn all sprites into static, and use a static sensor as my placeable piece. PROBLEM: static-to-static collisions not fired

QUESTION
Are collisions only fired when a dynamic object is involved? It seems that any other combination of sensor, kinematic and static won’t fire any collision (event listener: “collision”) at all. Any idea on how to accomplish this?

Thanks! [import]uid: 27243 topic_id: 8851 reply_id: 308851[/import]

So I found the solution :slight_smile:

Make everything in the level a static sensor, set gravity to 0,0, and use a dynamic body for the piece being placed.

Then (but I still have to test this) at level start make everything a regular body (as opposed to sensor), re-set non static parts of the level as dynamic and set gravity to point downward. [import]uid: 27243 topic_id: 8851 reply_id: 32287[/import]