I have a problem with Box2D, namely I want to make a damper/absorber for car in my game, everything works good but one part of damper fall out from the other like in movie: http://www.youtube.com/watch?v=gBPnfOLwbmg.
code of joint and bodies:
Thanks;)
code of joint and bodies:
Code: Select all
BodyDef amorDef=new BodyDef();
amorDef.type=BodyType.DynamicBody;
amorDef.position.set(50, 100);
amorBody=world.createBody(amorDef);
PolygonShape ksztaltamor=new PolygonShape();
ksztaltamor.setAsBox(7.0f, 30.0f);
FixtureDef fixamorDef=new FixtureDef();
fixamorDef.shape=ksztaltamor;
fixamorDef.density = 3.1f;
fixamorDef.friction = 10f;
fixamorDef.restitution = 0.3f;
amorBody.createFixture(fixamorDef);
BodyDef amorDef2=new BodyDef();
amorDef2.type=BodyType.DynamicBody;
amorDef2.position.set(amorBody.getPosition().x, amorBody.getPosition().y+20);
amorBody2=world.createBody(amorDef2);
PolygonShape ksztaltamor2=new PolygonShape();
ksztaltamor2.setAsBox(10.0f, 30.0f);
FixtureDef fixamorDef2=new FixtureDef();
fixamorDef2.shape=ksztaltamor2;
fixamorDef2.density = 3.1f;
fixamorDef2.friction = 10f;
fixamorDef2.restitution = 0.3f;
amorBody2.createFixture(fixamorDef2);
amor1=new PrismaticJointDef();
amor1.initialize(amorBody, amorBody2, amorBody.getWorldCenter(), new Vector2(0,1));
amor1.lowerTranslation=-0.2f;
amor1.upperTranslation=0.0f;
amor1.enableLimit=true;
amor1.maxMotorForce=20.5f;
amor1.motorSpeed=4.0f;
amor1.enableMotor=true;
world.createJoint(amor1); Thanks;)