I’ve largely followed the code from Controlling a Physical Vehicle and TestFancyCar.java and I’ve got a little red vehicle mesh driving around a custom-made racetrack.
But with bulletAppState.setDebugEnabled(true)
showing the CollisionShape, I can see that the CollisionShape jiggles about relative to the actual graphical vehicle mesh, so that at some points the CollisionShape is adrift by as much as twenty percent of the vehicle width. Periodically the CollisionShape will then pop back into place so that it’s perfectly aligned with the rendered vehicle mesh again.
Is this jiggle/drift expected, or is it likely that I’ve done something wrong when creating the vehicle and the physics control?
The method which creates the vehicle is:
private void initVehicle() {
carNode = new Node();
carNode.setShadowMode(RenderQueue.ShadowMode.Cast);
Spatial carModel = assetManager.loadModel("Models/bareCoop.j3o");
Spatial carSpatial = findSpatial(carModel, "chassis_node");
Geometry carBody = findGeom(carModel, "chassis");
carBody.setLocalScale(2.0f);
carSpatial.setMaterial(createChassisMaterial());
HullCollisionShape vehicleShape = new HullCollisionShape(carBody.getMesh());
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
compoundShape.addChildShape(vehicleShape, new Vector3f(0, 0, 0));
compoundShape.addChildShape(new BoxCollisionShape(new Vector3f(0.6f, 0.2f, 1.0f)), new Vector3f(0, 0.6f, 0));
player = new VehicleControl(compoundShape, 121.80f);
carNode.addControl(player);
initialiseSuspension();
initWheels(carModel);
carNode.attachChild(carSpatial);
rootNode.attachChild(carNode);
bulletAppState.getPhysicsSpace().add(player);
}