Unwanted Bouncing Behavior When Converting Display Groups to Physics Bodies

Hi @crawfdc47,

Yes, the multi-element body must be associated with only one object. However, if the objects in your “group” are going to remain unified in position/relation, then you can use any one of those bodies as the basic to construct that body’s element and additional elements representing the other objects in the group.

Of course, if your group objects will move independently of each other, then they should obviously be individual physics objects.

Brent

Hi Brent,

Yes, I would like the objects in the group to remain unified in position/relation so that they behave as a single body. However, I am still not sure exactly how to write the code to apply the multi-element body to one of my objects, while adding the rest of the child objects of my display group as elements to that body I am apply physics to. The objects that I am trying to unify using display groups from the code I provided before are:

tile

tile.letterText

tile.pointValue

I could not find any examples or documentation online that shows specifically how to construct multi-element bodies from separate display objects. But, if I try applying the multi-element body to the ‘tile’ object, and then add the rest of these objects as elements to the ‘tile’ object multi-element body, the below code is what I come up with:

physics.addBody( tile, 'dynamic', {shape = tile}, {shape = tile.letterText}, {shape = tile.pointValue }, { friction = 0, bounce = 0, density = 0, radius = .5\*tileWidth } )

However, this code does not look right to me, and the grouped objects do not behave as a unified, single bodies in the simulator. Am I missing something?

Hi @crawfdc47,

I should ask another question: is this simulation going to work under the effect of gravity and other forces?

Brent

Hi Brent,

Yes, this simulation is supposed to work under the effect of gravity, but it is unlikely that I will be applying any other kinds of forces to the objects/bodies in this simulation. The only purpose really for adding gravity, is so that when one or more of the letter tiles is removed (when the user finds a word) the next tile on top of the removed tile falls in to replace the position of the removed tiles. This is the reason why the tiles are arranged in a grid-like manner. I hope that makes sense…

there are (at least?) two conceptual ways to use display groups:

  1. the stuff they contain are positioned individually to screen coordinates, group itself is left at 0,0 - this is fine for controlling visual “layering” but isn’t the way you’d want to do it for physics

  2. the stuff they contain are positioned relative to 0,0 origin of the group, then the group is positioned at screen coordinates - this is how you want to use it for physics

adding a physics body will “control” the xy of one display object.  if that object is a group, then its bounds needs to match its position - which only happens with setup 2) above.

An analogy for 2) is to think of your group as a small box sliding around a table:  first you put stuff “IN” the box (by giving them 0,0 relative coords), then you slide the box to where you want it - that makes physics happy and looks right on screen.  The analogy for 1) is a big sheet of clear plastic with its corner at the table’s corner, it’s contents spread all over the table - yes, sliding the plastic will slide the objects too, but not in a way that physics “likes”.

Hi davebollinger. Thanks for your input about using display groups. I tried implementing your second suggestion by changing line 17 of the code I provided above to:

tile.x, tile.y = .5\*tileWidth, .5\*tileWidth

However, this did not seem to improve the issue with bouncing behavior that I have been having. Thanks for the tip though!

I still have not found a way to fix the problem I was having with display groups, so I instead implemented sprites to achieve the type of physics behavior I wanted for the app. Rather than combining text with shapes into display groups, I instead created a 26 frame image sheet, with each frame representing a letter of the alphabet. I am guessing this method is less memory efficient than using display groups, but the physics seems to be working better.