I'm making a game, where you go on a bike through some hills. I have a problem with creating joints between bike's frame and it's wheels - the joints stretch somehow, they are not firm.
I've tried some different joints with different setup, but it always happened. I want no amortization, just firm joints between my bike and it's wheels.
This is the setup, I use now:
mFrame = new Frame(pX, pY, pPhysicsWorld);
mWheelFront = new Wheel(pX + 47.0f, pY - 28.0f, pPhysicsWorld);
mWheelRear = new Wheel(pX - 53.0f, pY - 28.0f, pPhysicsWorld);
this.attachChild(mWheelFront);
this.attachChild(mWheelRear);
this.attachChild(mFrame);
final RevoluteJointDef revoluteJointDefFront = new RevoluteJointDef();
revoluteJointDefFront.initialize(this.mFrame.getBody(), this.mWheelFront.getBody(), this.mWheelFront.getBody().getWorldCenter());
revoluteJointDefFront.collideConnected = false;
revoluteJointDefFront.maxMotorTorque = 100f;
pPhysicsWorld.createJoint(revoluteJointDefFront);
final RevoluteJointDef revoluteJointDefRear = new RevoluteJointDef();
revoluteJointDefRear.initialize(this.mFrame.getBody(), this.mWheelRear.getBody(), this.mWheelRear.getBody().getWorldCenter());
revoluteJointDefRear.collideConnected = false;
revoluteJointDefRear.maxMotorTorque = 100f;
pPhysicsWorld.createJoint(revoluteJointDefRear);
What do I do wrong? How to get those "firm" joints?
Possibly solutions:
Scale the world, to make size of moving bodies between 0.1 and 10 meters. Box2D manual says:
Continuous collision does not handle joints. So you may see joint stretching on fast moving objects.
If you are using bad scaling, then velocity maybe very high.
Increase count of position and velocity iterations. Box2D manual says:
The suggested iteration count for Box2D is 8 for velocity and 3 for position. You can tune this number to your liking, just keep in mind that this has a trade-off between speed and accuracy.
Make smaller time step (and increasing fps, to keep physic speed normal). From my experience, time step 1/60 sec is good, 1/30 not so good, but still working, 1/20 quite unstable, and can simulate only simple models.
ps your ground body is not optimal :) There can be smaller count of fixtures. It is specially important, if you programming for mobile platforms.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.