VehicleControl "brake" method doesn't work

Hi Guys,
My issue with VehicleControl is simple - brake method doesn’t work. I have tried to apply different amount of braking force (100, 1000) but it looks like it doesn’t affect the car at all.

Any one know what might be the problem?
Thanks a lot,
Adi

Can you show some code, because in my vehicle demo showcase I use the brake method extensively and it works fine.

Since the brake force is a continuous force (does not need to be updated per-frame) the only way I can see that wouldn’t work is that if part of your code was setting the brake force to zero after setting the force initially.

1 Like
        if(am.physicalControl instanceof VehicleControl) {

            ((VehicleControl)am.physicalControl).brake(brake.floatValue());
        }

It’s such a simle code…
I’ll check if anywhere in my code there is a setting of zero braking force

And here is the VehicleControl setup function. I do not set the braking anywhere in my code to zero…

   public void switchModelToCarMode(AppModel am, Quaternion initRotate) {

        Node model;
        model = am.model;

        float stiffness = am.resource.stiffness;// 120.0f;//200=f1 car
        float compValue = am.resource.compression;// 0.2f; //(lower than damp!)
        float dampValue = am.resource.damping;//  0.3f;
        final float mass = am.resource.mass;

        Spatial carNode = model.getChild(0);


        carNode.setShadowMode(RenderQueue.ShadowMode.Cast);
        Geometry chasis = findGeom(carNode, am.resource.chassis);
        BoundingBox box = null;//(BoundingBox) chasis.getModelBound();


        CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
        VehicleControl modelCtl = new VehicleControl(carHull, mass);


        model.addControl(modelCtl);
        am.physicalControl = modelCtl;

        //Setting default values for wheels
        modelCtl.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
        modelCtl.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
        modelCtl.setSuspensionStiffness(stiffness);
        modelCtl.setMaxSuspensionForce(10000);


        Vector3f wheelDirection = new Vector3f(0, -1, 0);
        Vector3f wheelAxle = new Vector3f(-1, 0, 0);

        Geometry wheel_fr = findGeom(carNode, am.resource.frontRightWheel);
        wheel_fr.center();
        box = (BoundingBox) wheel_fr.getModelBound();
        float wheelRadius = box.getYExtent();
        float back_wheel_h = (wheelRadius * 1.7f) - 1f;
        float front_wheel_h = (wheelRadius * 1.9f) - 1f;
        modelCtl.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
                wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

        Geometry wheel_fl = findGeom(carNode, am.resource.frontLeftWheel);
        wheel_fl.center();
        box = (BoundingBox) wheel_fl.getModelBound();
        modelCtl.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
                wheelDirection, wheelAxle, 0.2f, wheelRadius, true);

        Geometry wheel_br = findGeom(carNode, am.resource.backRightWheel);
        wheel_br.center();
        box = (BoundingBox) wheel_br.getModelBound();
        modelCtl.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
                wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

        Geometry wheel_bl = findGeom(carNode, am.resource.backLeftWheel);
        wheel_bl.center();
        box = (BoundingBox) wheel_bl.getModelBound();
        modelCtl.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
                wheelDirection, wheelAxle, 0.2f, wheelRadius, false);

        modelCtl.getWheel(2).setFrictionSlip(am.resource.backRightWheelFrictionSlip);
        modelCtl.getWheel(3).setFrictionSlip(am.resource.backLeftWheelFrictionSlip);

        bulletAppState.getPhysicsSpace().add(modelCtl);

        if(initRotate!=null) {
            modelCtl.setPhysicsRotation(initRotate.multLocal(modelCtl.getPhysicsRotation()));
        }

    }

What is your Vehicle show case? can I see the code?

Its on the store, source is on github.

https://store.jmonkeyengine.org/3de43b72-ddd9-4fd1-b653-ac79cc56df4e

1 Like

Thanks! This so cool!! I’m going to try embed your lib. instead of the “raw” vehicle control.

1 Like

Thanks jayfella.
Can you make it Java 1.7 compatible? I had to disable quite a few code in order to make it work in my project…