0

I am making an android top down game. There are circle bodies moving on a table. I apply forces to them but they move forever. They never stop moving. I want them to act like they are moving on table. There should be a friction between ground and the other bodies but I couldnt managed to do it. I have tried adding a body under others but it didnt worked. I thought about using FrictionJoint but there are no examples or tutorial about how to use them with andengine.

Arda Kara
  • 501
  • 6
  • 24
  • I think this question might fit for you needs http://gamedev.stackexchange.com/questions/33959/andengine-density-elasticity-friction-gravity-concepts – lakshman Jun 24 '14 at 11:34
  • Friction joint is made for this purpose so I would recommend trying it. The usage should be pretty much the same regardless of which programming language you're using. – iforce2d Jun 24 '14 at 11:53
  • Thanks but manual didnt help me because there is only a sentence about FrictionJoint which explains what is it but not how to use it. Also I found something about FrictionJoint but it is written in another language and constructors and usages arent same in java. – Arda Kara Jun 24 '14 at 11:55

1 Answers1

0

I managed to solve my problem and here is the solution:

We should create a body out of the scene which will apply friction to our bodies. And we should create jointDef's for each of bodies. Here is the code:

Body mFrictionBody;

mFrictionBody = PhysicsFactory.createBoxBody( mPhysicsWorld, -50, -50, 0, 0, BodyType.StaticBody, FIXTURE_DEF);

FrictionJointDef frictionDef = new FrictionJointDef();
frictionDef.bodyA = mFrictionBody;
frictionDef.bodyB = mMaviParaBody[0];
frictionDef.maxForce = 4.2f;
frictionDef.collideConnected = false;

mFriction[0] = (FrictionJoint) mPhysicsWorld.createJoint( frictionDef );
Arda Kara
  • 501
  • 6
  • 24