Objects not colliding

Hi everyone,

This is my first attempt at an app and it is based on the traditional bubble shooter game (shoot a colored bubble at target bubbles above if 3 or more of the same colour bubbles are touching remove the bubbles).
I have managed to create the target bubbles in a separate bubble.lua class by using a 2d array in a 9x9 grid. I have added physics to these bubbles and have made them static.

function bubble.new(x, y) – constructor

bubbleTable = { {“redbubble.png” } , { “bluebubble.png” } , { “greenbubble.png” } }

newBubble = { }

newBubble.image =display.newImage ( ( bubbleTable[math.random( 1,3 )][1] ), x, y)
physics.addBody( newBubble.image, “static”, { density=2.9, friction=0.1, bounce=0.2, radius=(d/2) } )

return setmetatable( newBubble, bubble_mt )
end

I’ve also created a blue bubble to act as the bubble being fired from the bottom of the screen. I have added physics to it and made it kinematic and added a touch event listener to fire the bubble
physics.addBody( bubbleBlue, “kinematic”, { density=2.9, friction=0.1, bounce=0.2, radius=d/2 } )

function fire(event)

if(event.phase == “began”) then
–Do something during the began phase
txt.text = "Began Phase “…event.x…” = x “…event.y…” = y "
display.getCurrentStage():setFocus(event.target, event.id)
startForceX = event.x; startForceY = event.y

elseif(event.phase == “moved”) then
–Do something during the moved phase
txt.text = event.x…" = x “…event.y…” = y Moved"

elseif(event.phase == “ended”) then
–Do something when the phase has ended
txt.text = event.x…" = x “…event.y…” = y Ended"
display.getCurrentStage():setFocus(event.target, nil)
endForceX = event.x; endForceY = event.y

bubbleBlue:setLinearVelocity( (startForceX - endForceX), (startForceY - endForceY) )

end
end

My problem is that once the bubble is fired it pass over the bubbles i have created. however when i remove “static” from the target bubbles which makes them fall to the bottom of the screen, they do collide with the bubble to be fired.

Thank you in advance for any help [import]uid: 163580 topic_id: 30197 reply_id: 330197[/import]

If I am not mistaken, “Kinematic” and “Static” physics objects do not interact with each other. You might have to attempt making all of the balls “Kinematic” or at least the ones at the top and ball you shoot could be “dynamic” [import]uid: 19620 topic_id: 30197 reply_id: 120937[/import]

When posting code always wrap it in the lua tags. it makes it so much easier to read.

IIRC kinematics won’t collide with static. It’s pretty much just dynamic vs kinematic or dynamic vs static. Change your bullet ball to dynamic. [import]uid: 147305 topic_id: 30197 reply_id: 120938[/import]

Some useful info on body types: http://developer.coronalabs.com/reference/index/bodybodytype :slight_smile: [import]uid: 52491 topic_id: 30197 reply_id: 120961[/import]

Thanks for the response i have changed the body type from kinematic to dynamic. My problem now is that the bubble to be fired is subjected to gravity when i do not want it to be. I simply want to know how to fire the bubble which is positioned down the bottom center of the screen at the target bubbles above. i’ve tried applyForce to the object but it doesn’t move. i want to be able to touch a point on screen and for the object to be fired in the direction of that point at a constant velocity.

Thanks again! [import]uid: 163580 topic_id: 30197 reply_id: 120984[/import]

@walshesimon welcome to one of Corona’s **fun** problems to deal with.

Gravity is global and can’t be set on an individual object. Contrary to the documents, which says that kinematic objects are just like dynamic objects except they are not affected by gravity. But that’s not true. Kinematic objects don’t generate collisions with static objects like a dynamic object does – contrary to the documentation – I wish Corona Labs would give us collisions with Kinematic objects or give us the ability to just turn off gravity of certain objects. Almost every app where I need collisions that I can’t do with distance or rectangle overlap checks needs physics and in every case I’ve wanted something to not be affected by gravity.

Now of course you can set the global gravity to 0 and the problem kind of solves itself, unless of course you want gravity to affect things like particles or in your case, you want the hit balls to fall a little before they disappear. I worked around this once by applying my own 9.8 meter/second/second force to objects to get them to fall. Nasty hack.

Peach can you find out and explain why we can’t have Kinematic objects generate collisions like they should? [import]uid: 19626 topic_id: 30197 reply_id: 121022[/import]

thanks robmiracle for the response i currently have my global gravity set to 0 and i have my bubble to be fired set up in such a way that it when i touch the top of the screen and pull back at an angle it fires the bubble in the angle that i’ve pulled back. This is fine however the velocity at which the bubble travels at is not constant and often falls too short of the target bubbles.

thanks again [import]uid: 163580 topic_id: 30197 reply_id: 121024[/import]

@Rob - Good question, I will try and get you an answer on Monday :slight_smile: [import]uid: 52491 topic_id: 30197 reply_id: 121114[/import]

@rob, We implement Box2D (v2.2.1) and to my knowledge we don’t change any of the Box2D behavior. The only thing we change is the terms used to describe behavior and add “began” and “ended” phases to collisions. [import]uid: 7559 topic_id: 30197 reply_id: 121178[/import]

Okay, I did a little research on Box2d about this and it appears that this is a limitation of the Box2d engine, which is sad.

Based on my research I would suggest rewriting the language used at:
http://developer.coronalabs.com/content/game-edition-physics-bodies

o static bodies don’t move, and don’t interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
o dynamic bodies are affected by gravity and collisions with the other body types.
o kinematic objects are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.

with this:

o static bodies don’t move, and don’t interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
o dynamic bodies are affected by gravity and collisions with the other body types.
o kinematic objects are like static bodies, but they can be moved and are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.

Where as the previous language makes one believe that dynamic and kinematic objects are the same with the exception of gravity.

None of this changes the fact that we need collisions to trigger on objects that have no gravity. [import]uid: 19626 topic_id: 30197 reply_id: 121180[/import]

@Rob,

I updated the Physics page with your text for Kinematic objects. Thanks. [import]uid: 7559 topic_id: 30197 reply_id: 121183[/import]

If I am not mistaken, “Kinematic” and “Static” physics objects do not interact with each other. You might have to attempt making all of the balls “Kinematic” or at least the ones at the top and ball you shoot could be “dynamic” [import]uid: 19620 topic_id: 30197 reply_id: 120937[/import]

When posting code always wrap it in the lua tags. it makes it so much easier to read.

IIRC kinematics won’t collide with static. It’s pretty much just dynamic vs kinematic or dynamic vs static. Change your bullet ball to dynamic. [import]uid: 147305 topic_id: 30197 reply_id: 120938[/import]

Some useful info on body types: http://developer.coronalabs.com/reference/index/bodybodytype :slight_smile: [import]uid: 52491 topic_id: 30197 reply_id: 120961[/import]

Thanks for the response i have changed the body type from kinematic to dynamic. My problem now is that the bubble to be fired is subjected to gravity when i do not want it to be. I simply want to know how to fire the bubble which is positioned down the bottom center of the screen at the target bubbles above. i’ve tried applyForce to the object but it doesn’t move. i want to be able to touch a point on screen and for the object to be fired in the direction of that point at a constant velocity.

Thanks again! [import]uid: 163580 topic_id: 30197 reply_id: 120984[/import]

@walshesimon welcome to one of Corona’s **fun** problems to deal with.

Gravity is global and can’t be set on an individual object. Contrary to the documents, which says that kinematic objects are just like dynamic objects except they are not affected by gravity. But that’s not true. Kinematic objects don’t generate collisions with static objects like a dynamic object does – contrary to the documentation – I wish Corona Labs would give us collisions with Kinematic objects or give us the ability to just turn off gravity of certain objects. Almost every app where I need collisions that I can’t do with distance or rectangle overlap checks needs physics and in every case I’ve wanted something to not be affected by gravity.

Now of course you can set the global gravity to 0 and the problem kind of solves itself, unless of course you want gravity to affect things like particles or in your case, you want the hit balls to fall a little before they disappear. I worked around this once by applying my own 9.8 meter/second/second force to objects to get them to fall. Nasty hack.

Peach can you find out and explain why we can’t have Kinematic objects generate collisions like they should? [import]uid: 19626 topic_id: 30197 reply_id: 121022[/import]

thanks robmiracle for the response i currently have my global gravity set to 0 and i have my bubble to be fired set up in such a way that it when i touch the top of the screen and pull back at an angle it fires the bubble in the angle that i’ve pulled back. This is fine however the velocity at which the bubble travels at is not constant and often falls too short of the target bubbles.

thanks again [import]uid: 163580 topic_id: 30197 reply_id: 121024[/import]

@Rob - Good question, I will try and get you an answer on Monday :slight_smile: [import]uid: 52491 topic_id: 30197 reply_id: 121114[/import]

@rob, We implement Box2D (v2.2.1) and to my knowledge we don’t change any of the Box2D behavior. The only thing we change is the terms used to describe behavior and add “began” and “ended” phases to collisions. [import]uid: 7559 topic_id: 30197 reply_id: 121178[/import]

Okay, I did a little research on Box2d about this and it appears that this is a limitation of the Box2d engine, which is sad.

Based on my research I would suggest rewriting the language used at:
http://developer.coronalabs.com/content/game-edition-physics-bodies

o static bodies don’t move, and don’t interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
o dynamic bodies are affected by gravity and collisions with the other body types.
o kinematic objects are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.

with this:

o static bodies don’t move, and don’t interact with each other; examples of static objects would include the ground, or the walls of a pinball machine.
o dynamic bodies are affected by gravity and collisions with the other body types.
o kinematic objects are like static bodies, but they can be moved and are affected by forces but not by gravity, so you should generally set draggable objects to “kinematic”, at least for the duration of the drag event.

Where as the previous language makes one believe that dynamic and kinematic objects are the same with the exception of gravity.

None of this changes the fact that we need collisions to trigger on objects that have no gravity. [import]uid: 19626 topic_id: 30197 reply_id: 121180[/import]