Jump to content

How to Increase Rigidity of Arcade Sprite Bodies


jackrugile
 Share

Recommended Posts

I was curious if there is a way to increase the rigidity of arcade sprite bodies. At the moment, they seem to overlap quite a bit, and even fall through each other at times. You can see in the gif below (and demo) that a whole row gets lost.

 

Is there any way to completely get rid of this overlapping/fallingissue? If yes, can it be done with arcade physics, or do I need to switch to ninja or p2?

 

Demo of issue here: http://codepen.io/jackrugile/pen/0309643b449e772eba93fc9be3c8e7be/

 

aaXhGry.gif

Link to comment
Share on other sites

I don't think Arcade Physics is cut out for this kind of simulation. A few people now have tried to get multiple objects to stack, but run into issues such as this. I'd say try P2 if you need more realistic simulations, or if the above example is the sort of thing you're trying to make (I guess puzzle game mechanics similar to Candy Crush?) a non-physics based approach would work better, using grids and tweens to ensure everything is kept apart.

 

Here's an ugly hack which you probably should not use; you may be able to work this into something though:

update: function() {    this.physics.arcade.collide( this.dots, this.dots, function(dot) {       // discount 'sleep' implementation - this is ugly and not at all consistent      // we've not moved much last frame so assume we've come to rest and stop moving entirely      if (dot.body.deltaAbsY() < 1) {        dot.body.moves = false;      }    });},
Link to comment
Share on other sites

lewster32,

 

Thanks for your reply. I will look into P2 physics in the future if I ever need perfect stacking. You are right about the matching Candy Crush style game, that is what I was going for and thought it would save me some calculations if I just let the pieces fall with gravity rather than move them manually. Before your reply I actually went down that path with grids and tweens and it works great for this situation. Thanks!

 

That is a clever hack, too! Thank you.

Link to comment
Share on other sites

  • 1 year later...

I was curious if there is a way to increase the rigidity of arcade sprite bodies. At the moment, they seem to overlap quite a bit, and even fall through each other at times. You can see in the gif below (and demo) that a whole row gets lost.

 

Is there any way to completely get rid of this overlapping/fallingissue? If yes, can it be done with arcade physics, or do I need to switch to ninja or p2?

 

Demo of issue here: http://codepen.io/jackrugile/pen/0309643b449e772eba93fc9be3c8e7be/

 

aaXhGry.gif

this link is dead will you please fix it . 

Link to comment
Share on other sites

  • 8 months later...

I just found a weird solution on accident. If you do something like this inside update

             game.physics.arcade.collide(LobbyPlayerGroup);
             game.physics.arcade.collide(LobbyPlayerGroup, LobbyPlayerGroup)

(LobbyPlayerGroup reference = this.dots)

It fixes the "falling through" issue. If you remove either line, it will break again though. Both collide method lines must be used in that same order. This is probably taxxing on the CPU... but eh, if its for something temporary, don't notice any performance issues it's temp solution for now. (For arcade physics) -- P2 would be ideal as lewst already stated :)

 

Edit:

Wait, it seems like the overlapping is caused by the amount of velocity.  So, for a temporary fix for this, just add a new 'game.physics.arcade.collide(LobbyPlayerGroup);' line:

For example, if it's starting to overlap/squish your objects, add two collides:

 game.physics.arcade.collide(LobbyPlayerGroup);

 game.physics.arcade.collide(LobbyPlayerGroup);

--And if you increase velocity again, and it collides, add another, and so on.  This does work but as I said, CPU is getting hammered I think, so I wouldn't recommend... this but I think it's kind of a funny solution :lol:

 

Link to comment
Share on other sites

  • 1 month later...

I'm recently encountering a similar problem! I have to use physics because it is easier for me to add velocity to the blocks! Did anyone manage to recreate the same scenario using P2 Physics? Setting mine to P2 seems to make it act weird, pieces scattering all over the place!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...