Hi!
Is it possible to change the center of mass of a vehicle to lower it so the car doesn’t overturn that easily?
Thanks
Hi!
Is it possible to change the center of mass of a vehicle to lower it so the car doesn’t overturn that easily?
Thanks
Yes. You simply need to use an asymmetrical CollisionShape
such as HullCollisionShape
.
Alternatively, you can achieve a similar effect with any shape using the roll-influence factor.
public VehicleAutoShop initializeChassis(){
//create a compound shape and attach the CollisionShape for the car body at 0,1,0
//this shifts the center of mass of the spatial to 0,-1,0
//create vehicle node
chassis.setLocalScale(2.2f,2.2f,2.2f);
chassis.setLocalTranslation(new Vector3f(0, 1, -0.2f));
vehicleNode=new Node("vehicleNode");
vehicleNode.attachChild(chassis);
return this;
}
public VehicleAutoShop initializeCamera(){
ChaseCamera chaseCam=new ChaseCamera(JmeGame.gameContext.getCamera(), vehicleNode);
chaseCam.setDefaultDistance(-15f);
chaseCam.registerWithInput(JmeGame.gameContext.getInputManager());
chaseCam.setDragToRotate(true);
return this;
}
public VehicleAutoShop initializeVehiclePhysics(){
CompoundCollisionShape compoundShape = (CompoundCollisionShape)CollisionShapeFactory.createDynamicMeshShape(chassis);
//this shifts the effective center of mass of the CollisionShape to 0,-1,0
compoundShape.translate(new Vector3f(0,1,0));
vehicle = new VehicleControl(compoundShape, 600f);
vehicleNode.addControl(vehicle);
return this;
}
I hope this helps…
Thanks for your comments
@sgold Currently I’m creating the physics shape as follows:
CollisionShape carCShape = CollisionShapeFactory.createDynamicMeshShape(chasis);
The “chasis” is a geometry which was manually modelled to be a simple collider, so getting through the code of “createDynamicMeshShape”, in the end it’s creating a HullCollisionShape, but it’s too high still. Am I missing something?
About the roll-influence factor, you mean calling vehicleControl.setRollInfluence to any value lower than 1, right?
@Pavl_G so the key line here would be compoundShape.translate(new Vector3f(0,1,0));
whichs would be the one really moving the center of mass 1 unit below, right?
Aha, yes as docs states above
Btw, If you are going to create a VehicleControl, cast the result to the subclass CompoundCollisionShape
createDynamicMeshShape()
puts the center of mass at (0,0,0) in model space. Using Spatial.move()
you can adjust the mesh positions relative to the model origin.
Yes.
Such a cast would either fail or have no effect.
I remember last time VehicleControl required me a CompoundCollisionShape as parameter to provide a compound collision for vehicle chassis + wheels, or I am missing something…
Well VehicleControl
doesn’t require it, but compoundShape.translate()
would.
Hi guys!
Thanks for all you replies but I don’t find it clear still…
This is one of the models I’m using:
All cars are designed in the same way so according to this comment:
would the default center of mass be below the car (at the origin of the model file) or am I not understanding your comment properly?
Also, if using spatial.move before creating the VehicleControl doesn’t seem to change anything, the car overturns same way as before.
I’ve tried also the compoundShape.translate()
approach creating a compound collision shape manually because I’m creating the dynamic mesh shape from a geometry. The code is as follows:
Geometry chasis=CarModelHelper.searchChasis(playerNode);
CollisionShape carHullInner = CollisionShapeFactory.createDynamicMeshShape(chasis);
CompoundCollisionShape carHull = new CompoundCollisionShape(1);
carHull.addChildShape(carHullInner);
carHull.translate(new Vector3f(0,0.5f,0));
player = new VehicleControl(carHull, mass);
And it’s even worse, the hull seems to be upper than before and in fact it’s show as such in the debug view:
Regular:
using translate:
From RHR, this would be -0.5f though
I always use my right hand when it comes to axes presented in the scene…lol…that if I didn’t rotate the node openGL uses RHR.
Yes, that’s where I’d expect it to be. And based on the physics debug images you posted, I think it is. Notice how the arrows to the wheels originate from a point below the car. That’s your center of mass.
So now I want to understand why you think the center of mass is somewhere else…
Ooook, got it! I just thought the center of mass was upper because how the car behaved overturning that much but maybe I should check other physic properties of the vehicle control
Thank you both!
I think the main problem arising, from which the car overturns, may be emerging from the Car Suspension
properties, in which stiffness may be very high, mass may be low & damping(shock Absorber) is bigger than compression(shock producer), low axle length with big wheels…that may overturns the car, but changing the effective center to a little bit downward should also protect from overturning, but in the presence of a good suspension action is the most important attribute, Monster cars have a high effective center, but still donot overturn, because of their good mass & suspension properties…
May be you can look on real cars Suspension factors & apply them in code…,this may also helps :
calling it in :
This PDF may help you with other ideas too :
https://sbel.wisc.edu/wp-content/uploads/sites/569/2018/05/Real-time-Vehicle-Simulation-for-Video-Games-Using-the-Bullet-Physics-Library.pdf
Thanks for the detailed explanation. I’ll work on this