Revolute joint and Prismatic Joint

Hi,

I have doubt how both Revolute and Prismatic Joints are working together. I do not know how to increase the speed of the bike by using these joints.

My code is like this

leftWheelRevoluteJoint.SetMotorSpeed(15*Math.PI * (kbd.isKeyPressed(40) ? 1 : kbd.isKeyPressed(38) ? -1 : 0));
leftWheelRevoluteJoint.SetMaxMotorTorque(kbd.isKeyPressed(40) || kbd.isKeyPressed(38) ? 17 : 0.5);

rightWheelRevoluteJoint.SetMotorSpeed(15*Math.PI * (kbd.isKeyPressed(40) ? 1 : kbd.isKeyPressed(38) ? -1 : 0));
rightWheelRevoluteJoint.SetMaxMotorTorque(kbd.isKeyPressed(40) || kbd.isKeyPressed(38) ? 12 : 0.5);

leftAxlePrismaticJoint.SetMaxMotorForce(30+Math.abs(800*Math.pow(leftAxlePrismaticJoint.GetJointTranslation(), 2)));
leftAxlePrismaticJoint.SetMotorSpeed(-10*Math.pow(leftAxlePrismaticJoint.GetJointTranslation(), 1));

rightAxlePrismaticJoint.SetMaxMotorForce(20+Math.abs(800*Math.pow(rightAxlePrismaticJoint.GetJointTranslation(), 2)));
rightAxlePrismaticJoint.SetMotorSpeed(-10*Math.pow(rightAxlePrismaticJoint.GetJointTranslation(), 1));

carBody.ApplyTorque(30*(kbd.isKeyPressed(37) ? -1: kbd.isKeyPressed(39) ? 1 : 0));

Can anyone help me?
I think you need to explain the problem better. Just quickly looking at the code it seems like it would work ok... to help people understand what you are thinking, try to mention:
What are you expecting to happen?
What did you try to make it happen? (and don't just say 'everything' 🙂
What is happening instead?
i want to increase the speed of the bike movement.

What should i do to increase the speed?
By increasing the setMotorSpeed and SetMaxMotorTorque of revolute joint
or
by increasing the SetMaxMotorForce and SetMotorSpeed of prismatic joint.


can you understand me?
ok, got it.
What did you try to make it happen?
What is happening instead?
i'm trying to increase the speed but i never seen any changes in the speed of the bike.
I see.
What did you try to make it happen?
i changed the setMotorSpeed and SetMaxMotorTorque in the update event to increase the speed.

Is it correct?

This is the code done in update event.

world.Step(1/30,10,10);// was world.Step(1/30, 10);
if ((hero_mc.x <=275.3 || bgSettingArray[levelNumber][0].x >= bgSettingArray[levelNumber][3]) &&(hero_mc.x >=275.3|| bgSettingArray[levelNumber][0].x <=bgSettingArray[levelNumber][2] ))
{
screen.x -= hero_mc.x - 275.3 ;
bgSettingArray[levelNumber][0].x = screen.x + bgSettingArray[levelNumber][1];
}
hero_mc.x = carBody.GetPosition().x * 30;
hero_mc.y = carBody.GetPosition().y * 30;
hero_mc.rotation = carBody.GetAngle() * (180 / Math.PI);

if(leftWheelRevoluteJoint)
{
leftWheelRevoluteJoint.SetMotorSpeed(25*Math.PI * (kbd.isKeyPressed(40) ? 1 : kbd.isKeyPressed(38) ? -1 : 0));
leftWheelRevoluteJoint.SetMaxMotorTorque(kbd.isKeyPressed(40) || kbd.isKeyPressed(38) ? 25 : 0);
}
if(rightWheelRevoluteJoint)
{
rightWheelRevoluteJoint.SetMotorSpeed(25*Math.PI * (kbd.isKeyPressed(40) ? 1 : kbd.isKeyPressed(38) ? -1 : 0));
rightWheelRevoluteJoint.SetMaxMotorTorque(kbd.isKeyPressed(40) || kbd.isKeyPressed(38) ? 17 : 0);
}
if(leftAxlePrismaticJoint)
{
leftAxlePrismaticJoint.SetMaxMotorForce(30+Math.abs(800*Math.pow(leftAxlePrismaticJoint.GetJointTranslation(), 2)));
leftAxlePrismaticJoint.SetMotorSpeed(-10*Math.pow(leftAxlePrismaticJoint.GetJointTranslation(), 1));
}
if(rightAxlePrismaticJoint)
{
rightAxlePrismaticJoint.SetMaxMotorForce(20+Math.abs(800*Math.pow(rightAxlePrismaticJoint.GetJointTranslation(), 2)));
rightAxlePrismaticJoint.SetMotorSpeed(-10*Math.pow(rightAxlePrismaticJoint.GetJointTranslation(), 1));
}
carBody.ApplyTorque(30*(kbd.isKeyPressed(37) ? -1: kbd.isKeyPressed(39) ? 1 : 0));

// this is new!
world.ClearForces()
for (var currentBody:b2Body=world.GetBodyList(); currentBody; currentBody=currentBody.GetNext()) {
// getting cart x position
if (currentBody.GetUserData()!=null)
{
if (currentBody.GetUserData().name == "hero_mc")
{
currentBody.GetUserData().x = (currentBody.GetPosition().x + 0.1) * 30 + screen.x;
}
else
{
currentBody.GetUserData().x = currentBody.GetPosition().x * 30 + screen.x;

}
currentBody.GetUserData().y=currentBody.GetPosition().y *30 + screen.y;
}
if (currentBody.GetPosition().x*worldScale<(x*-1)-640)
{
world.DestroyBody(currentBody);
}
}
// this is new!!
world.DrawDebugData();
}
Ok. It looks like you are doing it correctly, but the world.ClearForces() could be a problem. I think that should come just after the world.Step(), otherwise the ApplyTorque will be cancelled.

Is the bike moving at all? You just said the speed didn't change, so I assumed you could drive it along ok but it would not go faster than a certain speed. If it's not moving at all, maybe the torque of the motor is too small - try a really high value to see if anything changes.

Otherwise, if the bike is already moving but not fast enough, you will just need to adjust the value you give to SetMotorSpeed for the revolute joints.

Another problem with this situation can be that the wheel slips a lot on the ground, so you will need to give both the ground and the wheel fixtures a high friction value, like between 0.9 - 1.0
The bike is moving but only a certain speed.
if i change the SetMotorSpeed Value also the speed is same not fast enough.
Should i need to change the SetMaxMotorForce or SetMotorSpeed for prismatic joint?

Original thread: https://box2d.org/forum/viewtopic.php?t=7909