How do I stop my physics car from easily flipping over?

Additionally, it looks like your hull shape is way too low, making it bump into the ground when the suspension is compressed.

This is what you want :slight_smile:

1 Like

Heā€™ll probably say ā€œthis is just the Google Doc that is linked in the javadoc and wiki, I donā€™t understand how that is supposed to help me.ā€ :wink:

Well, thereā€™s nothing there specifically related to vehicle roll, other than setRollInfluence(), which does not affect anything when used in my code. :confused:

I have been using JBullet for over 4 years, read the wiki pages, etc. However I simply cannot find anything to solve this specific problem.
(I guess what Iā€™m saying is, why would I have come here without researching the issue first?)

That doesnā€™t mean Iā€™m a good programmer thoughā€¦ So feel free to point out the thing that magically solves my issue which I have totally missed.

Am currently experimenting with stabilizer wheels. Only problem is, they are bad in confined spaces.

I told you what the problem in the video is (the chassis bouncing into the ground) and how you can change the center of mass, which is what ALL games do to make their vehicles more stableā€¦ Funny how so many people got working non-rolling cars in less than 4 yearsā€¦

[quote=ā€œnormen, post:25, topic:36948, full:trueā€]How you can change the center of mass
[/quote]
This is my problem - I canā€™t work out how to do it. I can put the collision shapes higher up, but then my car associated with the collision shape still stays in the center, which now clips through the terrainā€¦ And I cannot work out how to put a node at a huge bias higher up.
I mightā€™ve been using JBullet for 4 years, but Iā€™ve only been using JME since January. Donā€™t expect a JME expert here. :stuck_out_tongue:

Just because Iā€™ve been using JBullet for 4 years doesnā€™t mean Iā€™ve worked with cars for 4 years. It is only in the last three or four months I have used cars at all - I was previously working on a plane game.

Ummā€¦ you say you donā€™t know how to move a Spatial that is attached to a Node? Then you shouldnā€™t be messing with physics yet at allā€¦ Anyway, I copy-pasted the relevant code from TestPhysicsCar and added the secret code to attach a model to that node with an offset (but donā€™t show this to anybody else, its occult knowledge!)

    //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
    //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0
    CompoundCollisionShape compoundShape = new CompoundCollisionShape();
    BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
    compoundShape.addChildShape(box, new Vector3f(0, 1, 0));

    //create vehicle node
    Node vehicleNode=new Node("vehicleNode");
    vehicle = new VehicleControl(compoundShape, 400);
    vehicleNode.addControl(vehicle);

    // MYSTERIOUS WAY TO ADD MODEL HERE!!
    Spatial vehicleModel = assetManager.loadModel("Models/MyCar.j3o");
    vehicleModel.setLocalTranslation(0,1,0);
    vehicleNode.attachChild(vehicleModel);

Edit: Oh and remember, your hull is still bouncing into the ground, put your wheels further down.

Hm. Interesting I didnā€™t think of that.

Meh.

What makes you believe that? The collision model is nowhere near the ground and never has been. If youā€™re referring to the visual model, then Iā€™m using a different collision model.

The fact that in your GIF the suspension stops compressing when the vehicle falls over.

1 Like

@normen Setting the centre to be lower simply isnā€™t working. it completely messes up car rotation in terms of pitch and roll, as it is trying to pitch forward from a center point way below the actual physics. It creates very bad looking unnatural physics.

Thank you for the suggestion anyway, but stabilizer wheels appear to be the much better option.

Thanks all. Will try to find a more permanent solution for the future.

https://gyazo.com/b832440a6e8614e673a852af76537b3f.png

https://gyazo.com/11716428e3ade642fbda8e132384b2b3.png

Wheels outside of the hull will create all kinds of other issues. Try driving along a wall with your stabilizer wheels. Setting the center of mass lower is definitely working, thats why ALL games do it. But anyway, Iā€™ll drop out of this thread now. Good luck with your game.

Alright. Will attempt to lower the center of mass when I have time. I can see why it is a viable solution - Perhaps I just lowered it too much.

Luckily I donā€™t have many any walls in my game. But, when I do, then I see your point.

Thanks for the assistance. Appreciate it.

And maybe try to set the ā€œinertia tensorā€ in the bullet physics engine. Thatā€™s basically a matrix which contains the integral (or ā€œsumā€) of mass elements along all three major axes. Set it in such a way that most of your mass elements are near the bottom of the vehicle and closer to the engine block.

Donā€™t know if setting the com (center of mass) is equivalent to this solution and if itā€™s even possible with bullet to set the inertia tensor. The book about physics that I read described a physics engine that letā€™s you set the inertia tensor and it contained several examples like boxes, bottles, etc.