Different Drive types of vehicles

Is there a way of making vehicles drive around using differential drives (controlling the wheels on each side of the vehicle) and/or treads like tanks use? How might each side be controlled?

Theres a method accelerate(int wheel, float force)

Ahh, so each wheel would be accelerated, I was thinking one for each side. This works great! thanks!

I can’t get this to work. I can’t control the TestPhysicsCar because I think the wheels don’t have WheelNumbers I can address them using vehicle.accelerate(WheelNumber, Force); I tried printing vehicle.getWheelInfo(0); and it shows null. I’m just not understanding how to address the wheels.

In my attempts to drive the car with differential steering, I replaced the “Lefts” and “Rights” in the onAction with the following code:

[java] if (binding.equals(“Lefts”)) {


if (value) {

vehicle.accelerate(0, 0.5f);

vehicle.accelerate(1, 0.5f);

} else {

vehicle.accelerate(0, -0.5f);

vehicle.accelerate(1, -0.5f);



} else if (binding.equals(“Rights”)) {

if (value) {

vehicle.accelerate(2, 0.5f);

vehicle.accelerate(3, 0.5f);

} else {

vehicle.accelerate(2, -0.5f);

vehicle.accelerate(3, -0.5f);


Well, did you add the wheels in the first place?

I personally didn’t because they are already attached in the PhysicsCar example. Is there a different method for adding the wheels than that?

It works fine for me. I guess you were checking for the wheel when it wasn’t yet attached and your forces are too low or the wheels work against each other.

I’m checking for the wheel when the “Lefts” button is pressed. I’m still getting a null from " System.out.println(vehicle.getWheel(0).toString());" The wheels are definitely attached by the time I press the buttons because I can still accelerate straight by pressing the “Ups” button.

Would you mind posting what code you tested and found to work?

Oh, you try to print the name with toString, its null, that might be true, but if you can call toString() on it the object is definitely not null :P. To test I just set the acceleration of the wheels to work against each other when accelerating, TestPhysicsCar replace line 218 with:







Result: The vehicle turns (although slow due to friction)

Ahh, ok. thanks clearing that part up for me. I’ll test this sometime this week and hopefully won’t have any more problems with it.