Vehicle spinning around

Hey,



I just startet playing around with jbullet-jme and it looks really cool, but i got a Problem with the PhysicsVehicleNode.



So this is how i try to use it:

physicsCar=new PhysicsVehicleNode(carBody,CollisionShape.ShapeTypes.BOX);
        physicsCar.setFrictionSlip(0.8f);
        physicsCar.setMaxSuspensionTravelCm(20);
        physicsCar.setMass(250);
        
        float stiffness=190;//200=f1 car
        float compValue=0.2f; //(lower than damp!)
        float dampValue=0.5f;
        physicsCar.setSuspensionCompression(compValue*2.0f*FastMath.sqrt(stiffness));
        physicsCar.setSuspensionDamping(dampValue*2.0f*FastMath.sqrt(stiffness));
        physicsCar.setSuspensionStiffness(stiffness);
        
        
        
        Vector3f wheelDirection=new Vector3f(0,-1,0);
        Vector3f wheelAxle=new Vector3f(-1,0,0);
        
        // Front left
        physicsCar.addWheel(wheel1, new Vector3f(0.7f,0.4f,1.2f), wheelDirection, wheelAxle, 0.13f, 0.34f, true);
        physicsCar.setRollInfluence(0, 1);

        // Front right
        physicsCar.addWheel(wheel2, new Vector3f(-0.7f,0.4f,1.2f), wheelDirection, wheelAxle, 0.13f, 0.34f, true);
        physicsCar.setRollInfluence(1, 1);

        physicsCar.addWheel(wheel3, new Vector3f(0.7f,0.4f,-1.2f), wheelDirection, wheelAxle, 0.13f, 0.34f, false);
        physicsCar.setRollInfluence(2, 1);

        physicsCar.addWheel(wheel4, new Vector3f(-0.7f,0.4f,-1.2f), wheelDirection, wheelAxle, 0.13f, 0.34f, false);
        physicsCar.setRollInfluence(3, 1);

        
        physicsCar.setLocalScale(3.5f);
      physicsCar.setLocalTranslation(new Vector3f(-20,2,0));
      rootNode.attachChild(physicsCar);
        physicsCar.updateRenderState();
      
      
      pSpace.add(physicsCar);



The Node carBody, as the name already says, only contains the Car-Body and the wheel-Nodes are all clones from one wheel.

First it starts falling until it hits the ground. This works now, after it took me some time to get the (hopefully) right values for the suspension-stuff.
But as soon as i try to accelerate the vehicle just starts spinning around like crazy and falls through the ground.

Do you have any Idea what i'm doing wrong?

Dennis
normen said:

Simple solution is dont change the mass after creation, set it in the constructor already. Setting the mass after creation is bound to produce problems atm.


I'm not changing the mass after creation it's done in the constructor.


                BoxCollisionShape boxcs = new BoxCollisionShape((Node) vehicle);
                vehiclePhysics = new PhysicsVehicleNode(vehicle, boxcs, 600);

What is the acceleration value? Maybe it is set too high? Also, when using a big box (few vertices) as floor the vehicle might get problems, try if it works better on a terrain or something with more vertexes. Getting bullet vehicles to work smoothly can be a bit hard I have to admit.

Hi,



i just tried to change the acceleration-value but i didn't change.

And i already use some kind of Terrain.

It's a model i made with Cheetah3d and the ground has 1024 Polygons, so i think that should be enough.

And with the Vehicle from the Test everything works fine on the Terrain.



I think the problem lies somewhere else.

I made small movie, to show you whats happening:

http://bazinga.ld-network.de/vehicleProblem.mov

There you can see what happens as soon as i try to accelerate.

It still looks as if the acceleration was way too high… Try reducing the weight of the car and/or make the suspensionRestLength longer. Strange things are also more likely to happen when the stiffness is set too high.

I played around with the values, but it still didn't change.

Currently i think that it's gotta be something with my model, because i tried putting the Vehicle into your Test.

The Tires worked, but as soon as i add the Car-model instead of the Box it starts going crazy.

And if i replace the carmodel in my example with a box it works just fine. So i guess there is something wrong with the model.

Are there any requirements at the Car-Model?



If somebody wants to check out the Model, I got it from here:

PSIONIC GAMES & RETRO VANDAL ART

The only thing i changed is, that i removed the tires.

Ah, might be that when you create the PhysicsNode, the BoundingVolume of the model is not computed right. Try creating the BoxCollisionShape before and use that to create the PhysicsNode. And dont use setMass() on the PhysicsNode, set the mass in the constructor, there is some bullet problem with setting the mass after constructing the RigidBody.

Thanks for your help, but it still doesnt work…



This is how I create the Vehicle currently:

BoxCollisionShape boxCollisionShape=new BoxCollisionShape((BoundingBox)body.getWorldBound());
        physicsCar=new PhysicsVehicleNode(body,boxCollisionShape,250);



The BoundingBox looks also right around the Car, but it still doesn't really work.

Any other Idea?

Maybe if you got some time you can look over it. I integrated it into your TestSimplePhysicsCar example.

Dennis

As said, the error is probably within the bounds of the car, so dont use it, create your BoxCollisionShape like this:



BoxCollisionShape boxCollisionShape=new BoxCollisionShape(new Vector3f(x,y,z));

Hi,

i'm sorry to bother you again, but it still won't work.

I did like you said and created my own BoxCollisionShape with the x/y/z-Values:

BoxCollisionShape boxCollisionShape=new BoxCollisionShape(new Vector3f(0.23f,.14f,.5f));


In the javadoc it says, that this should be the halfExtent, so i figured it should be half of the size. Is this right?
Anyways, i tried both ways, but with both basically the same thing happened.
The Vehicle was first falling down and as soon as it hits the ground it spins around a little (not as bad as before) and then stops in the air. It looks as if the Vehicle is flying above the ground. So i tried changing the values so that it would hit the ground, but as soon as it hits the ground, is goes crazy again.

But the x/y/z-Values should be right. The old ModelBox has the same extends and in Cheetah3d i also got the same values, only doubled, so i guess they should be right.

Yes, thats right, the halfextents are half the box's size. Dont know right now whats the problem there, maybe I can have a look at your project when I come home from work. One last thing you could try is lowering the weight of the car and see if that solves the problem.

Ok, I looked at the thing and there are several problems.

First one is when you add the wheels:

physicsCar.addWheel(wheel3, new Vector3f(0.7f,0.4f,-1.2f), wheelDirection, wheelAxle, 0.13f, 0.34f, false);


The vector has a positive y-value which means that the wheel is attached *above* the suspension, not below, set that to a negative value and the car stops jumping around.

Second, you should not scale your PhysicsNode after you have created the CollisionShape for it, scale the attached nodes before and then create the CollisionShape from it. Although jbullet-jme will try to adapt the CollisionShape size currently when setLocalScale is used, this feature will be removed because the CollisionShape might be shared with other PhysicsNodes.

Hope this helps,
Normen

Hi,

it finally works :slight_smile: Thank you! You're doing a great job around here!

I think i got about 10 years older while working on it, i just couldn't figure out what i did wrong.



As you said i moved the Wheels down and scaled the Nodes up first and then created the CollisionShape and now it works.



Dennis

Hello



I'm trying to do simple car simulation with JMonkey and JBullet-Jme. I'm very new to JMonkey and having many problems, but hopefully everyday I'm getting experienced but there is still a lot of things to learn. I've read almost every posts related to the PhysicsVehicle and followed Normen's suggestion to apply physics to my car. But still getting some strange results. Everytime I change some values (like mass, comp or damp etc …) I get different results like spinning, sinking, sometimes it just doesn't move. I'm really stuck with this.



Here is my code.



                BoxCollisionShape boxcs = new BoxCollisionShape((Node) vehicle);
vehiclePhysics = new PhysicsVehicleNode(vehicle, boxcs, 600);

vehiclePhysics.setFriction(0.8f);
vehiclePhysics.setMaxSuspensionTravelCm(20);

// 0.0 - Offroad buggy, 50.0 - Sports car, 200.0 - F1 Car
float stiffness = 80.0f;// 200=f1 car
float compValue = 0.2f; // (lower than damp!)
float dampValue = 0.5f;
vehiclePhysics.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
vehiclePhysics.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
vehiclePhysics.setSuspensionStiffness(stiffness);

// Should be rotated before adding wheels
vehicle.rotateUpTo(new Vector3f(0, 0, -1));

// Getting Tires
Node a = (Node) vehicle;
Spatial lfw = a.getChild("VPRedT01");
Spatial rfw = a.getChild("VPRedT03");
Spatial lbw = a.getChild("VPRedT00");
Spatial rbw = a.getChild("VPRedT02");

// Scaling tires
lfw.setLocalScale(0.1f);
rfw.setLocalScale(0.1f);
lbw.setLocalScale(0.1f);
rbw.setLocalScale(0.1f);

Vector3f wheelDirection = new Vector3f(0, -1, 0);
Vector3f wheelAxle = new Vector3f(-1, 0, 0);
BoundingBox wheelBoundry = (BoundingBox) lfw.getWorldBound();
float wheelRadius = wheelBoundry.yExtent / 2; // It's around 0.3
float suspRestLength = 0.15f;

// Left Forward Wheel = lfw
vehiclePhysics.addWheel(lfw, new Vector3f(0f, 0f, 11.5f),
wheelDirection, wheelAxle, suspRestLength, wheelRadius, true);

vehiclePhysics.addWheel(rfw, new Vector3f(0f, 0f, 11.5f),
wheelDirection, wheelAxle, suspRestLength, wheelRadius, true);

vehiclePhysics.addWheel(lbw, new Vector3f(0f, 0f, -11f),
wheelDirection, wheelAxle, suspRestLength, wheelRadius, false);

vehiclePhysics.addWheel(rbw, new Vector3f(0f, 0f, -11f),
wheelDirection, wheelAxle, suspRestLength, wheelRadius, false);

vehiclePhysics.setLocalTranslation(new Vector3f(20, 30, 20));

rootNode.attachChild(vehiclePhysics);
vehiclePhysics.updateRenderState();
physicSpace.add(vehiclePhysics);[/sup]




Another problem is when I steer front tires rotation of the tires looks odd, it's like applied translation after rotated.

Please help

Simple solution is dont change the mass after creation, set it in the constructor already. Setting the mass after creation is bound to produce problems atm.

Finally got it working. The problem was in my 3ds model. Thanks Normen for sharing me piece of his work. You are very appreciated and good luck.