Multiform objects and their mass

Hello

In my game I need to create different physical objects with different shape.

An object can also be made of ten shapes. My problem is that all objects regardless of shape and number of pieces must have the same mass, same bounce, etc.(For example, a ball should behave like a five-piece star) Is this possible?

Maybe.  I’m not sure if you can change the density of an object after body addition, but if so, then you can adjust the mass.

The bounce setting is simple.  Just set it to the same value.  The bounce ‘response’ however, is dependent upon mass.

Well it looks like changes to density after the fact make no difference.  However, by setting the density appropriately in advance, you can get the same mass.
 
Here is a simple case for a rectangle (using SSK2 display object builders because I’m too lazy to use longhand code).

local rectA = ssk.display.newRect( nil, 100, 100, { size = 100 }, { } ) local rectB = ssk.display.newRect( nil, 250, 100, { size = 75 }, { density = (100^2)/(75^2) } ) print(rectA.mass, rectB.mass)

prints

 11.111112594604 11.111113548279

 

In all honest, except for the simplest of geometric shapes, you’ve got no hope of doing this.

Basically, you need to choose a object A of a specific area as your base, then set density for all other objects based on the equation 

density if areaA/areaB, where areaB is the “other object’s” area.

So, as long as you have the area equations for your shapes you should be golden.

Question what body shapes are you using?

  • Square (default) - Visual shape is based on image, not body geometry.
  • Circle - Even easier to work out density.
  • Shape Matches Visual Shape - Good luck on this.

The difference is minimal indeed.

But with multiform bodies? Is it enough to divide by the number of pieces?

One way to hack this is to give the shapes TWO bodies.

  1. Very low density form fitting body that matches your collision requirements.

  2. One very small circular body with a specific density, where all shapes have the same circular body radius.

Body 2 gives the majority of the mass, while body 1 is used for collisions.

Shape Matches Visual Shape… 

Maybe I have an idea but I do not know if I can talk to you

No, I don’t think so.  You should experiment however.

Your last idea is more or less mine :smiley:

A problem I don’t hear you talking about here is center of mass.  If your shapes are arbitrary, then the center of mass will be offset.  However, if you try to force ‘same’ mass, this will be complicated and may not behave as expected.

You are right.

But the user can choose from a large set of images and I would like the shape of the object not to influence its behavior

If it was possible to put a Shape Matches Visual Shape with mass 0 and joint a standard sphere could work though … right? The problem though I think it would be to make a Shape Matches Visual Shape with 0 mass

Do you mean 0 density?  You can’t set mass.

Also, you can’t have 0 density.  Very small density like 1e-9 sure, but not zero.

Setting density == 0 is the same as not setting density.

According to you is an acceptable result? Can it work? Or is it a forcing?

I don’t understand this question…

Works or doesn’t work I might be able to help with, but ‘acceptable’ versus ‘unacceptable’ is  subjective and up to you.

you are right.

I essentially wondered if it could work or create problems that I did not anticipate. But now I do some tests

Maybe.  I’m not sure if you can change the density of an object after body addition, but if so, then you can adjust the mass.

The bounce setting is simple.  Just set it to the same value.  The bounce ‘response’ however, is dependent upon mass.

Well it looks like changes to density after the fact make no difference.  However, by setting the density appropriately in advance, you can get the same mass.
 
Here is a simple case for a rectangle (using SSK2 display object builders because I’m too lazy to use longhand code).

local rectA = ssk.display.newRect( nil, 100, 100, { size = 100 }, { } ) local rectB = ssk.display.newRect( nil, 250, 100, { size = 75 }, { density = (100^2)/(75^2) } ) print(rectA.mass, rectB.mass)

prints

 11.111112594604 11.111113548279