Overlap Sliding

Given a composer scene with this -

function scene:create() local group = self.view cameraGroup = display.newGroup() mapGroup = display.newGroup() cameraGroup:insert(mapGroup) group:insert(cameraGroup) local tileSize = 500 physics.setDrawMode( "debug" ) physics.start() physics.setGravity(0,0) local solidTile = display.newRect(mapGroup, display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight) solidTile:setFillColor(209/255, 95/255, 95/255) physics.addBody(solidTile, { density=0, friction=0, bounce=0}) solidTile.bodyType = "static" local notSolidTile = display.newRect(mapGroup, display.contentCenterX, display.contentCenterY, tileSize, tileSize) notSolidTile:setFillColor(95/255, 209/255, 95/255) physics.addBody(notSolidTile) notSolidTile.gravityScale = 0 end

I end up with a green tile sliding to the right, inexplicably.

Given the underlying body is static, why is the notSolidTile sliding?

You’ve missed one important part about the physics engine and how it works.

There are three types of physics bodies: static, kinematic and dynamic. Static and kinematic bodies do not interact with other static or kinematic bodies, but dynamic bodies will interact with all types of physics bodies.

So, when you create a massive static body (solidTile) and then add a another massive dynamic body (notSolidTile) on top of it, they immediately collide with each other. The static body cannot move, but since the two physics bodies cannot overlap, the physics engine tries to push the dynamic object (that can be moved) away in order to resolve the issue.

If you want to create a dynamic body that doesn’t collide with other bodies, you need to use collision filters or make turn the body into a sensor.

Thank you. This is born from a top-down demo I’m trying to make.

I have a complex sprite I’m using as bounds for physics, which is sensorA.
Making collision “walls” around sensorA for every segment is impractical, due to there being over 150 of them (and they vary based on graphics.getOutline).
Is there any way to have a sensor (sensorA) within the bounds of another sensor (surroundSensorB), then use the surroundSensorB to act as a solid for bodies on sensorA (basically making bounds by occlusion)?

I don’t really understand what you mean.

You can have as many sensors as you want overlapping each other.

Are you trying to create physics bodies for images via graphics.newOutline() and then keep things inside of them? If so, then I don’t think that there is a way to make it work. The only way I’d see that working is if you used a chain body, since chain bodies are hollow and the only physical parts that’d collide would be the exterior lines themselves.

You’ve missed one important part about the physics engine and how it works.

There are three types of physics bodies: static, kinematic and dynamic. Static and kinematic bodies do not interact with other static or kinematic bodies, but dynamic bodies will interact with all types of physics bodies.

So, when you create a massive static body (solidTile) and then add a another massive dynamic body (notSolidTile) on top of it, they immediately collide with each other. The static body cannot move, but since the two physics bodies cannot overlap, the physics engine tries to push the dynamic object (that can be moved) away in order to resolve the issue.

If you want to create a dynamic body that doesn’t collide with other bodies, you need to use collision filters or make turn the body into a sensor.

Thank you. This is born from a top-down demo I’m trying to make.

I have a complex sprite I’m using as bounds for physics, which is sensorA.
Making collision “walls” around sensorA for every segment is impractical, due to there being over 150 of them (and they vary based on graphics.getOutline).
Is there any way to have a sensor (sensorA) within the bounds of another sensor (surroundSensorB), then use the surroundSensorB to act as a solid for bodies on sensorA (basically making bounds by occlusion)?

I don’t really understand what you mean.

You can have as many sensors as you want overlapping each other.

Are you trying to create physics bodies for images via graphics.newOutline() and then keep things inside of them? If so, then I don’t think that there is a way to make it work. The only way I’d see that working is if you used a chain body, since chain bodies are hollow and the only physical parts that’d collide would be the exterior lines themselves.