Bullet Vehicle problems

In case anybody is interested, I got the vehicle working in native bullet eventually. So it’s working in JME 3.1 now. If you copy the files in the zip file to a new BasicGame project, it should work: https://dl.dropboxusercontent.com/u/21307972/BasicGame.zip

The model is similar to the TestFancyCar model. The wheels are in the same model, not in a separate file. This is how the vehicle is set up now:

private void buildPlayer() {
    float stiffness = 60.0f;//200=f1 car
    float compValue = 0.29f; //(lower than damp!)
    float dampValue = 0.3f;
    final float mass = 400;

    //Load model and get chassis Geometry
    carNode = new Node();
    carNode.setShadowMode(ShadowMode.Cast);
    
    Spatial carModel = assetManager.loadModel("Models/Cars/Coupe_Green.j3o");
    Spatial carSpatial = findSpatial(carModel, "car");
    Geometry carBody = (Geometry)((Node)carSpatial).getChild(0);
    
    HullCollisionShape vehicleShape = new HullCollisionShape(carBody.getMesh());
    
    //Create a vehicle control
    player = new VehicleControl(vehicleShape, mass);
    carNode.addControl(player);
    
    player.setSuspensionCompression(compValue * 0.1f * FastMath.sqrt(stiffness));
    player.setSuspensionDamping(dampValue * 3f * FastMath.sqrt(stiffness));
    player.setSuspensionStiffness(stiffness);
    player.setMaxSuspensionForce(10000);
       
    setupWheel(carModel, "fl", true);
    setupWheel(carModel, "fr", true);
    setupWheel(carModel, "rl", false).setFrictionSlip(6f);
    setupWheel(carModel, "rr", false).setFrictionSlip(6f);
    
    carNode.attachChild(carSpatial);

    //rootNode.addLight(setupHeadlight(carSpatial, "fl"));
    //rootNode.addLight(setupHeadlight(carSpatial, "fr"));

    rootNode.attachChild(carNode);
    getPhysicsSpace().add(player);
    
    chaseCam = new ChaseCamera(cam, carNode, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setDefaultDistance(40);
}

private VehicleWheel setupWheel(Spatial carModel, String suffix, boolean isFrontWheel) {
    Spatial wheel = findSpatial(carModel, "wheel_" + suffix);
            
    BoundingBox box = ((BoundingBox)wheel.getWorldBound());
    Vector3f wheelPosition = box.getCenter();
    float radius = box.getYExtent();
    float maxSuspensionTravel = 10f;
    float restLength = maxSuspensionTravel / 50.0f;
    
    List<Spatial> list = ((Node)wheel).getChildren();
    for (int i = 0; i < list.size(); i++) {
        list.get(i).setLocalTranslation(wheelPosition.negate());
    }
    
    VehicleWheel vw = player.addWheel(wheel, wheelPosition.add(0, restLength, 0),
            wheelDirection, wheelAxle, restLength, radius, isFrontWheel);
    vw.setMaxSuspensionTravelCm(maxSuspensionTravel);
    
    return vw;
}
3 Likes