Why i can't apply an angular impulse to a box2d body with 0 density?

Forums Programming physics: Box2d, Chipmunk et al Why i can't apply an angular impulse to a box2d body with 0 density?

This topic contains 11 replies, has 3 voices, and was last updated by  DifferentSparks 1 year, 5 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
Author Posts
Author Posts
November 10, 2012 at 7:27 pm #245241

DifferentSparks
Participant
@differentsparks

Why i can’t apply an angular impulse to a box2d body with 0 density?

And why even if i try to add a simple rotate action to the sprite it doesn’t allow the rotation?

Thanks

Edit. Seems that setting the angular velocity directly works.. always.. why?

November 10, 2012 at 7:44 pm #391902

slembcke
Administrator
@slembcke

Because the body would have zero mass, and any forces or impulses applied to it would need to be divided by the mass giving you an infinite amount of acceleration.

November 10, 2012 at 7:54 pm #391903

DifferentSparks
Participant
@differentsparks

I understand, but why if i do like:

_tuftBody->ApplyLinearImpulse(b2Vec2(10,0), _tuftBody->GetWorldCenter());

with _tuftBody that has 0 density, works properly ?

November 10, 2012 at 8:38 pm #391904

slembcke
Administrator
@slembcke

That’s a good question actually. What is “works properly” in this case?

If the body really has no mass, then the correct response would be that the body’s velocity should end up being infinite. If “works properly” is implying that it’s giving you a finite result, then there is definitely a bug somewhere. If you print out the mass of a 0 density body, what does it say it is?

November 10, 2012 at 10:09 pm #391905

iforce2d
Participant
@iforce2d

Dynamic bodies that would have no mass (due to either having no fixtures at all, or only fixtures without volume eg. edge/chain) are given a mass of 1. I believe this is done to allow them to remain dynamic without any natural mass of their own. Why rotational inertia is not handled in the same way though, is indeed a good question.

November 11, 2012 at 8:39 am #391906

DifferentSparks
Participant
@differentsparks

By “works properly” i meant that the impulse is applied to the body.

i asked the mass by GetMass and the result is :

1.000000

but my density is 0 in the plist.

I had to use a 0 density body because this body is attached to another one(main body) by a revolute joint. and the main body reacts strangely to impulses and forces if the body attached with the joint has a density>0.

So ApplyLinearImpulse works, ApplyAngularImpulse doesn’t but SetAngularVelocity does.

November 11, 2012 at 9:28 pm #391907

iforce2d
Participant
@iforce2d

You should not need to set the density for dynamic bodies to zero. Since GetMass is returning 1 you effectively don’t have a zero density body anyway. I think we could use some more info on the overall goal you’re trying to achieve, might help.

November 12, 2012 at 6:22 am #391908

DifferentSparks
Participant
@differentsparks

Well, i have a boss, made by one big sprite (the boss’s body) and one smaller(the tuft). i attached the tuft to the main body by a revolute joint,

revJointDef.Initialize(_tuftBody, _boss._bossBody,
_tuftBody->GetWorldPoint(b2Vec2(-self.contentSize.width/3/PTM_RATIO2, 0/PTM_RATIO2)) );

and simply move around the boss and with him the tuft too. all seems to work, except when the density of the tuft’s body is >0, also a value of 0.0001 has bad effects on the main body.

November 12, 2012 at 6:54 am #391909

iforce2d
Participant
@iforce2d

What are the bad effects? I’m guessing you want things to behave as if the tuft was weightless and not affect the boss at all? Physics engines are usually not designed to deal with bodies that have zero mass, so the best you could do is make the mass of the boss much larger than the tuft. For example, I would have expected that using an extremely small density for the tuft would be ok… what are the masses of the two bodies when you do that?

I can’t tell from your code, but is the revolute joint anchor at the center of the boss body?

November 12, 2012 at 8:03 am #391910

DifferentSparks
Participant
@differentsparks

A bad effect is for example that applying an angular impulse to the boss body , the mass of the tuft just stop the rotation after some second(is not enabled the angular limit).

Tuft’s mass: 1.000000

Boss’s mass: 20.550596

The boss density is 2.

Don’t think i’ve anchored it

b2RevoluteJointDef revJointDef;
revJointDef.Initialize(_tuftBody, _boss._bossBody,
_tuftBody->GetWorldPoint(b2Vec2(-self.contentSize.width/3/PTM_RATIO2, 0/PTM_RATIO2)) );
revJointDef.lowerAngle = CC_DEGREES_TO_RADIANS(-30.0f);
revJointDef.upperAngle = CC_DEGREES_TO_RADIANS(30.0f);
revJointDef.enableLimit = false;
//revJointDef.enableMotor = true;
//revJointDef.motorSpeed = 0.0f;
// revJointDef.maxMotorTorque = 1000.0f;
_joint = (b2RevoluteJoint*) _world->CreateJoint(&revJointDef);

November 12, 2012 at 2:09 pm #391911

iforce2d
Participant
@iforce2d

The point that you are passing to Initialize is where the anchor will be, is that the center of the boss body? If so, couldn’t it just be:

revJointDef.Initialize(_tuftBody, _boss._bossBody, _boss._bossBody->GetPosition() );

Initialize requires that the two bodies be positioned in the correct place already. If they are not, you can set the anchor positions in each body yourself – this might be helpful: http://www.iforce2d.net/b2dtut/joints-revolute

November 13, 2012 at 6:36 pm #391912

DifferentSparks
Participant
@differentsparks

They are already in the correct position, the tuft position is based on the boss position

bodyDef.position = _boss._bossBody->GetWorldPoint(b2Vec2(64/PTM_RATIO2, _boss.contentSize.height/3.0/PTM_RATIO2));

the anchor point then is not at the center of the boss but where the 2 sprites meet.

-self.contentSize.width/3/PTM_RATIO2, 0/PTM_RATIO2 // with self that is tuft's sprite

Could be that i attached the boss to the tuft and not the tuft on the boss? or doesn’t make difference?

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.