Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have made a bicycle with Box2D using several polygons for the frame at different angles connected using weld joints, and I have revolute joints on the wheels with a motor.

I have made some basic terrain (straight ground and a small ramp) and added keyboard input to control the bicycle with torque to balance it. All of this is done in with Box2D's Debug Draw.

When the bicycle is on its back wheel but diagonally forward (kinda like this position -> /) the motors just cause it go spinning backwards over when in reality it should either stay on its back wheel or go down onto both wheels.

Here's my code the revolute joints:

            //Front Wheel Joint

        var frontWheelJointDef:b2RevoluteJointDef = new b2RevoluteJointDef();
        frontWheelJointDef.Initialize(frontWheelBody, secondFrameBody, frontWheelBody.GetWorldCenter());
        frontWheelJointDef.enableMotor=true;
        frontWheelJointDef.maxMotorTorque=10000;
        frontWheelJoint = _world.CreateJoint(frontWheelJointDef) as b2RevoluteJoint;

        //Rear Wheel Joint

        var rearWheelJointDef:b2RevoluteJointDef = new b2RevoluteJointDef();
        rearWheelJointDef.Initialize(rearWheelBody, firstFrameBody, rearWheelBody.GetWorldCenter());
        rearWheelJointDef.enableMotor=true;
        rearWheelJointDef.maxMotorTorque=10000;
        rearWheelJoint = _world.CreateJoint(rearWheelJointDef) as b2RevoluteJoint;

And here's the relevant part of my update function:

            // up and down control wheels motor
        if (up) {
            motorSpeed-=0.5;
        }
        if (down) {
            motorSpeed += 0.5;
        }
        // left and right control cart torque
        if (left) {
            middleCentreFrameBody.ApplyTorque( -3);
            gearBody.ApplyTorque( -3);
            firstFrameBody.ApplyTorque( -3);
            secondFrameBody.ApplyTorque( -3);
            rearWheelToChainBody.ApplyTorque( -3);
            chainToFrontFrameBody.ApplyTorque( -3);
            topMiddleFrameBody.ApplyTorque( -3);
        }
        if (right) {
            middleCentreFrameBody.ApplyTorque( 3);
            gearBody.ApplyTorque( 3);
            firstFrameBody.ApplyTorque( 3);
            secondFrameBody.ApplyTorque( 3);
            rearWheelToChainBody.ApplyTorque( 3);
            chainToFrontFrameBody.ApplyTorque( 3);
            topMiddleFrameBody.ApplyTorque( 3);
        }
        // motor friction
        motorSpeed*=0.99;
        // motor max speed
        if (motorSpeed>100) {
            motorSpeed=100;
        }

        rearWheelJoint.SetMotorSpeed(motorSpeed);
        frontWheelJoint.SetMotorSpeed(motorSpeed);

Any ideas what might be causing this?

Thanks

share|improve this question
1  
Would it be possible to share a demonstration online? –  Zehelvion Sep 30 '12 at 16:39
    
This sounds a lot like your mass and friction values are off. Also I don't understand why you apply torque to all these different body parts? Applying a force to the motor alone should be sufficient to move the bike. –  bummzack Aug 29 '13 at 16:52

1 Answer 1

maxMotorTorque(10000) seems too much for me.

I don't think giving torque to each part separately will work.why don't you make one bike body and create parts as fixtures of it. Then give torque to the bike body.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.