Overlaping bodies

Hi all,

i’m desesperated because i don’t understand this and i can’t found the solution.

I attached a ejemplo.zip, here are a ej.jpg where you can see my problem.

Basically, my game is that we have a gear in rotation and we have to get moving other, placing them next.
The problem is correctly transmitting motion of a gear to another, overlapping gears.

if someone can tell me what i’m doing wrong, and could gave me a correct example.

I need some help, i’m going crazy!

Thanks for all.

Personally, I’m not going to open any attached zips, but if you paste your code I’ll take a look.

Just at a guess, though, I suspect what you’re doing wrong is trying to create a physics object by creating the outline of the gear in a single object. This is wrong because it will create a concave body which will not work in Box2D. Create your gear by create multiple bodies, one for each tooth on the gear. The multiple bodies will act as a single body and allow each gear to mesh with the others.

Also, make sure that the (0,0) location of every display group which contains physics bodies is at the same location.

Hi horacebury,

i use PhysicsEditor for create a correct Gear,

the body definition its this:

[lua]

“engra1shape”] = {
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -5, 17.5 , 6, 17.5 , 6, 30.5 , -5, 30.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 18, -4.5 , 12, -13.5 , 23, -20.5 , 29, -11.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 13, 12.5 , 18, 4.5 , 29, 10.5 , 24, 19.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -24, -19.5 , -13, -13.5 , -18, -4.5 , -29, -10.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -18, 4.5 , -12, 13.5 , -23, 19.5 , -29, 11.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 6, -17.5 , -5, -16.5 , -5, -30.5 , 5, -30.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -5, -16.5 , 6, -17.5 , 12, -13.5 , -5, 17.5 , -12, 13.5 , -18, 4.5 , -18, -4.5 , -13, -13.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 13, 12.5 , 6, 17.5 , -5, 17.5 , 12, -13.5 , 18, -4.5 , 18, 4.5 }
}
}[/lua]

https://docs.google.com/file/d/0B-88Zk7c3DwlR3V4Z3RzbjNOTEU/edit?usp=sharing

There is the code, you can see only the main.lua code if you want.

It’s to bigger to post it.

Thanks you

Hi.  Just a quick note.  In your code I noticed this:

categoryBits = 1000, maskBits = 10,

That looks an awful lot like you (or the tool) are assuming that the numeric values are treated as Binary Coded Decimal

The value for categroyBits and maskBits are decimal values, not binary.  If you mean for 1000 to mean 8, and 10 to mean 2, then the code should be written like this instead:

categoryBits = 8, maskBits = 2,

Sorry for the intrusion if I’m wrong about the way this was intended to be interpreted.

Personally, I’m not going to open any attached zips, but if you paste your code I’ll take a look.

Just at a guess, though, I suspect what you’re doing wrong is trying to create a physics object by creating the outline of the gear in a single object. This is wrong because it will create a concave body which will not work in Box2D. Create your gear by create multiple bodies, one for each tooth on the gear. The multiple bodies will act as a single body and allow each gear to mesh with the others.

Also, make sure that the (0,0) location of every display group which contains physics bodies is at the same location.

Hi horacebury,

i use PhysicsEditor for create a correct Gear,

the body definition its this:

[lua]

“engra1shape”] = {
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -5, 17.5 , 6, 17.5 , 6, 30.5 , -5, 30.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 18, -4.5 , 12, -13.5 , 23, -20.5 , 29, -11.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 13, 12.5 , 18, 4.5 , 29, 10.5 , 24, 19.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -24, -19.5 , -13, -13.5 , -18, -4.5 , -29, -10.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -18, 4.5 , -12, 13.5 , -23, 19.5 , -29, 11.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 6, -17.5 , -5, -16.5 , -5, -30.5 , 5, -30.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { -5, -16.5 , 6, -17.5 , 12, -13.5 , -5, 17.5 , -12, 13.5 , -18, 4.5 , -18, -4.5 , -13, -13.5 }
}
,
{
pe_fixture_id = “”, density = 5000, friction = 0, bounce = 0,
filter = { categoryBits = 1000, maskBits = 10, groupIndex = 0 },
shape = { 13, 12.5 , 6, 17.5 , -5, 17.5 , 12, -13.5 , 18, -4.5 , 18, 4.5 }
}
}[/lua]

https://docs.google.com/file/d/0B-88Zk7c3DwlR3V4Z3RzbjNOTEU/edit?usp=sharing

There is the code, you can see only the main.lua code if you want.

It’s to bigger to post it.

Thanks you

Hi.  Just a quick note.  In your code I noticed this:

categoryBits = 1000, maskBits = 10,

That looks an awful lot like you (or the tool) are assuming that the numeric values are treated as Binary Coded Decimal

The value for categroyBits and maskBits are decimal values, not binary.  If you mean for 1000 to mean 8, and 10 to mean 2, then the code should be written like this instead:

categoryBits = 8, maskBits = 2,

Sorry for the intrusion if I’m wrong about the way this was intended to be interpreted.