Thakur Abhishek
Thakur Abhishek

Reputation: 11

libgdx's btRaycastVehicle not following chassis and wheels correctly

I setup a btRaycastVehicle as shown by xoppa in bullet tests of libGdx. When vehicle is at low speed, then it works correctly. But as speed of vehicle goes on increasing, chassis and wheels tend to separate from each other. Distance between wheel to wheel and wheel to chassis increases and after that vehicle behaves in incorrect way. Then the whole vehicle sometimes rotates around an axis.

Upvotes: 1

Views: 221

Answers (1)

Dean Harding
Dean Harding

Reputation: 72658

I recently had the same problem. The issue seems to be that the MotionState's callbacks are being called on a different thread to the render function. In Xoppa's sample app (here, for anybody else reading along), the wheel transforms are being updated in the render thread. The fix was to do the wheel transform in the MotionState's callback as well:

@Override
public void setWorldTransform (final Matrix4 worldTrans) {
  transform.set(worldTrans);

  for (int i = 0; i < 4; i++) {
    vehicle.getWheelInfo(i).getWorldTransform().getOpenGLMatrix(wheels[i].transform.val);
  }
}

Now all the transforms get updated at the same time, and the wheels stick to the chassis.

Upvotes: 1

Related Questions