Physics Particles?

How to implement physics based particles. We’ve particles in cocos2d-x but how to add physics body to it so that they deflect on touch the physics surface.
Is it possible doing it through particles or other implementation is needed. If so then how?

Example:
1) Check video https://www.youtube.com/watch?v=JbcHjMxSESc
Here when the player-ball touches the wrong surface, it breaks into particles(physics based particles).
How to implement that?

2) Also check,


How they break the green line when the ball touches it.

I don’t think classic particle systems implement physics, so you should probably create your own system. You can find some info here if you are using box2d.

I suspect when the line breaks they simply remove the original body and replace it with several small bodies in the same position.

Yeah that’s what I also think, probably a small impulse value based on the distance from the ball on each new body afterwards.

remove with setVisible or safe delete ?

If you’re talking about the original body, you need to remove it also from the physics world. How to remove it depends on the implementation. Are you using a custom box2d world? Or the cocos integrated physics engine?

I don’t think you need to - just let the ball collide with the pieces - and they may collide with one another

If you used setVisible then the physics body would still exist and interact so you probably don’t want that (although you might if, for example, you wanted to put the obstacle back if the ball fell through it again)

But you probably need to remove the physical object from the world.

Ahm, I was thinking about the original body, the long one, before it breaks into pieces. You need to remove it so that the ball can pass trough it, or maybe just make it a sensor and generate the new bodies when the collision is detected. And by the way, I’m referring to the second example, the one embeded in the original post :stuck_out_tongue:

Oh, you were talking about the impulse… yeah that depends on the ‘feeling’ the developer wants to achieve, so probably just letting the ball collide with the pieces might be enough.

ok thanks for explanation :slight_smile:

I’ve no idea what’s happening with the post! :smiley: :smiley:

Don’t just concentrate on HOW the line is breaking… It’s most common implementation is obviously first having sprite and on collision replacing it with flying particles.

I am asking that how those miniature particles are made physics based! :stuck_out_tongue:
I mean, so many particles are there… To create that effect, it looks like it’s completely physics game, first of all…

Yeah probably. Also the link that you gave is not actually what I asked… May be the term “physics particles” looks matching with the link u gave.

Well if you know the length of the bar you want to split, you should first break that length in a sum of random numbers. You can do that somehow like this(very pseudocode :stuck_out_tongue:):

ArrayOfInt a;
while (length > 0)
{
  int s = Math.round(Math.random() * (length - 1)) + 1;
  a.push(s);
  length -= s;
} 

Afterwards just create new boxes with the same height as the original line and the widths from the new array. Position them one after another and that’s all. Attaching sprites to the physic boxes or adding the boxes to the world or space depends on your specific implementation of the physics world.

So yeah, it’s pretty much done manually, and it’s not really a particle system, just a lot of physic bodies.

I think they’re just lots of physics objects with a method of drawing them (e.g. physics sprites)

There’s no real difference between lots of sprites and particles, after all!

Depending on your use (mainly how graphically lovely you want the pieces to look) you could just use sprites, or draw the graphics yourself. In the example, there’s not hundreds of particles, so I don’t think a particle system would be necessary (indeed, it’s clearly not a particle system - it’s a physics simulation system)

I had a play just to see what it might be like - see https://youtu.be/6j6XHigsTFU

There are 100 pineapples as static bodies, which become dynamic bodies on collision. I drop an apple on them to start the destruction.

You can imagine from that that (with suitable graphics) it’s not difficult to do.

1 Like