Vehicle Raycasting gets high rotation and movement when colliding

Post Reply
ilygan
Posts: 2
Joined: Tue Jan 15, 2019 3:25 pm

Vehicle Raycasting gets high rotation and movement when colliding

Post by ilygan »

Hi everyone, I am trying to stabilize the colisions of my vehicle with the scene and even when It's more stable than the beginning, in some occasions when the vehicle's collision (especially when I use a propeller combined with one of the jumps that possesses the car) it starts to bounce mor than what it should be, making it spin around itself without control until it stabilizes.

The vehicle is made with Raycasting (adding a 3D model with Irrlicht) the physics of the scene are made with the plug in of Bullet in Maya. The force applied to the cara oscillates between 500 and 1500 depending on it's use and the car has a mass of 100.

Any idea of why it happens? There is some way to neutralize the rebound made by the car colliding with one of the walls as well as to limit the rotation applied on it?

If any part of the code is needed or any sample of how the car moves I'll add it, thanks in advance.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Vehicle Raycasting gets high rotation and movement when colliding

Post by drleviathan »

It sounds like the vehicle action is going semi-unstable. What is the duration of your substep? If it is too big perhaps decreasing it would increase stability.

A problem that I've encountered in the past is a bad inertia tensor. If the inertia tensor is too small for the torques being applied to the body then it will spin up too fast and it is possible to pump energy into the system so it goes completely unstable. Try artificially increasing the inertia tensor of the vehicle. This will definitely slow down the rotation response when the vehicle collides with walls, however it will also make it harder to stop turning once it gets spinning: perhaps you can tune it just right, or even modulate it on the fly depending on what you want to do: stay oriented or stop spinning.

Another trick I've heard about but haven't played with: you can artificially increase the gravity on the vehicle when all wheels are in contact with the ground (try 2x, 4x, 8x). When you aren't suffering from rotational instability this trick will make it harder to flip or tumble the vehicle. However, if you want to support vehicle jumps: once it is fully airborne you would want to drop the gravity back down to normal.
ilygan
Posts: 2
Joined: Tue Jan 15, 2019 3:25 pm

Re: Vehicle Raycasting gets high rotation and movement when colliding

Post by ilygan »

Thanks for answering drleviathan. Currently, my duration in every step (substep) is the calculation of the execution game time * 0.001f, giving a value between 0.017 and 0.018, with a maximum step number of 60. If I try to decrease this value, the game "slows down" and loses fluidity making everything go slower.

About the inertia, the only thing I apply to the car is the following one in the initialization of the car physics:

Code: Select all

void Jugador::InitCollide(btDynamicsWorld *world){
 
    PhysicsEngine *bullet = PhysicsEngine::getInstancia();
 
    // Initial position
    btTransform transfCar;
    transfCar.setIdentity();
    btVector3 posTranfCar = btVector3(player.initPos.X, player.initPos.Y, player.initPos.Z);
    transfCar.setOrigin(posTranfCar);
 
    // Motion State
    player.motionStateCar = new btDefaultMotionState(transfCar);
 
    // Gravity
    btTransform transf;
    transf.setIdentity();
    transf.setOrigin(btVector3(0,1,0));
    player.centerGravity = new btCompoundShape();
 
    // Collision
    btVector3 collide(player.coche->getScale().X, player.coche->getScale().Y, player.coche->getScale().Z);
    player.formCollide = new btBoxShape(collide);
 
    // Mass of the car
    player.mass = 100;
    btVector3 Inertia(0,0,0);
    player.formCollide->calculateLocalInertia(player.mass,Inertia);
 
    player.centerGravity->addChildShape(transf, player.formCollide);
 
    // Cuerpo del coche
    player.bodyCollideChassis = new btRigidBody(player.mass, player.motionStateCar, player.centerGravity, Inertia);
    player.bodyCollideChassis->setUserPointer((void *) player.coche);
 
    world->addRigidBody(player.bodyCollideChassis);
    // Ray coche
    btVehicleRaycaster* rayVehicle = new btDefaultVehicleRaycaster(world);
    btRaycastVehicle::btVehicleTuning tuning;
 
    player.vehicle = new btRaycastVehicle(tuning, player.bodyCollideChassis, rayVehicle);
 
    player.bodyCollideChassis->setActivationState(DISABLE_DEACTIVATION);
    player.bodyCollideChassis->setGravity(btVector3(0,-20,0));
   
    world->addVehicle(player.vehicle);
 
    // Update collisionable objects in the list.
    irr::core::list<btRigidBody *> objects = bullet->getObjects();
 
    objects.push_back(player.bodyCollideChassis);
 
    bullet->setObjects(objects);
 
    // Create the wheels
    addWheels(player.vehicle, tuning);
}
I do not know if there is something more that has to be added as I am still learning. If you see something missing, do not doubt on telling me, I would appreciate it.

About the gravity, I imagine that in case of frontal collissions between the car and the walls of the scene your solution would be helpful, but, in my case, having a jump and a double jump (this last one being directional) it may not solve all the problem as the hardest collissions to control are the ones that are made with the impacts of jumping into the walls.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Vehicle Raycasting gets high rotation and movement when colliding

Post by drleviathan »

If all your substepa are about 0.017 then your simulation rate is 1.0/0.017 ~= 59 Hz which should be sufficient for stability in most cases.

Your vehicle looks too light. I assume 100 means 100kg. First thing to try: increase the mass of your vehicle. This will also increase its inertia tensor and will make it less "responsive" to collision torques, which will help keep it stable. Try 2X, 4X, 8X etc observe how things change. You might be able to tune it just right.

The btVehicleTuning class has a number of public data members you can play with. I don't have much experience with vehicles so I will just point this out. These are the default values but I don't know what they mean:

Code: Select all

                m_suspensionStiffness(btScalar(5.88)),
                m_suspensionCompression(btScalar(0.83)),
                m_suspensionDamping(btScalar(0.88)),
                m_maxSuspensionTravelCm(btScalar(500.)),
                m_frictionSlip(btScalar(10.5)),
                m_maxSuspensionForce(btScalar(6000.))
If it were me... I would provide a slider for each parameter and then try the vehicle out while moving them around, just to get a feel for how each parameter affects the behavior.

Another thing to try, but only after tuning the mass and vehicle parameters: reduce the friction of your walls and vehicle. Less friction means less torque during collisions. You can also try reducing the restitution which represents a ratio of energy conservation during collisions. A restitution of 1.0 means "bouncy" and a value of 0.0 means "mush".

After all that then you could try artificially increasing the inertia tensor 2X, 4X, 8X, and gravity 2X, 4X, 8X.
stefanejro
Posts: 12
Joined: Sun May 20, 2018 6:57 pm

Re: Vehicle Raycasting gets high rotation and movement when colliding

Post by stefanejro »

Not sure it this will be applicable in your case, but I've had a similar problem with vehicle rolling over on sharper turns. What solved the issue in my case was setting origin of my compound shape slightly below zero.
Check the last answer in this post for exact code:
viewtopic.php?f=9&t=12112&p=40932#p40932
Post Reply