Have multiple moving balls that phase through each other but can collide with other static objects

I’m currently trying to replicate “Swipe Brick Breaker” a clone of one of the games made by 111% games

 

https://www.youtube.com/watch?v=NrjuN6Vx7KM <------ (this is what I’m trying to make)

 

I have multiple balls moving on screen but which can collide with bricks and bounce off of them but they cant also collide with other balls another “pushing” each other as they’re all “dynamic” physic bodies. I’ve thought of using different physics bodies to solve this but that didn’t work out for me. This is what I planned: 

 

I would like the balls to phase through each other like how kinematic bodies can’t collide with other kinematic bodies (hence they phase through one another). However I can’t make the moving balls into kinematic bodies as the bricks need to be static (if I set the balls to kinematic and bricks to dynamic, the balls end up pushing the bricks around rather than bouncing off of them).

 

Not sure if I’m missing anything so help would be greatly appreciated.  

 

 

Here’s what I have for the brick collisions: 

 

[spoiler]

[lua]
function onCollision(self, event)

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

if bullet.y + bullet.height * 0.5 < event.other.y + event.other.height * 0.5 and event == brick then
if hitchecky == true then
velocityY = -velocityY
hitchecky = false
event.other:removeSelf()
bricklocationx = event.other.x / 43 – find brick location
bricklocationy = event.other.y / 30
spawngrid[bricklocationx][bricklocationy] = 0 – reset array value
timer.performWithDelay( 20, changehitchecky )
end
end

if bullet.x - bullet.width * 0.5 > event.other.x - event.other.width * 0.5 and event == brick then
if hitcheckx == true then
velocityX = -velocityX
hitcheckx = false
event.other:removeSelf()
bricklocationx = event.other.x / 43
bricklocationy = event.other.y / 30
spawngrid[bricklocationx][bricklocationy] = 0

timer.performWithDelay( 20, changehitcheckx )
end
end

if bullet.x + bullet.width * 0.5 < event.other.x + event.other.width * 0.5 and event == brick then
if hitcheckx == true then
velocityX = -velocityX
hitcheckx = false
event.other:removeSelf()
bricklocationx = event.other.x / 43
bricklocationy = event.other.y / 30
spawngrid[bricklocationx][bricklocationy] = 0
timer.performWithDelay( 20, changehitcheckx )
end
end

if bullet.y - bullet.height * 0.5 > event.other.y - event.other.height * 0.5 and event == brick then
if hitchecky == true then
velocityY = -velocityY
hitchecky = false
event.other:removeSelf()
bricklocationx = event.other.x / 43
bricklocationy = event.other.y / 30
spawngrid[bricklocationx][bricklocationy] = 0
timer.performWithDelay( 20, changehitchecky )
end
end
end
end[/lua]

[/spoiler]

 

 

 

 

 

 

Hi @othe2jams,

This seems like a case easily solved by collision filters, outlined here:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

You can also use the convenient Collision Filters plugin which makes setting them up much easier:

https://docs.coronalabs.com/plugin/collisionFilters/index.html

Take care,

Brent

Hi @othe2jams,

This seems like a case easily solved by collision filters, outlined here:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#filtering

You can also use the convenient Collision Filters plugin which makes setting them up much easier:

https://docs.coronalabs.com/plugin/collisionFilters/index.html

Take care,

Brent