Vehicle demo - no friction?

Brunni
Posts: 3
Joined: Sun Sep 09, 2012 10:55 pm

Vehicle demo - no friction?

Post by Brunni »

Hello,

I tried the Vehicle Demo application bundled with Bullet 2.80 and it works fine except that there is no friction: if you accelerate with up and then release the key, the vehicle will keep the same speed forever.

I tried increasing the friction of the ground, like this (VehicleDemo.cpp, line 299):
btRigidBody *body = localCreateRigidBody(0,tr,groundShape);
body->setFriction(1000000);
It has no effect. Then I tried to understand the updateFriction method of btRaycastVehicle but it seems to nowhere take in account the friction of the groundObject.

So, am I doing something wrong? How can I enable friction for this kind of vehicles? (preferably depending on the ground type: sand, asphalt, etc.). Thanks!
fsxfreak
Posts: 10
Joined: Mon Sep 03, 2012 12:09 am

Re: Vehicle demo - no friction?

Post by fsxfreak »

You're applying a friction constant to the rigid body (chassis), and the chassis never makes any contact with the ground. Instead, you want to apply friction to each wheel of the btRaycastVehicle by changing each wheel's wheelinfo.

For example (lines 381 - 389) -

Code: Select all

		for (int i=0;i<m_vehicle->getNumWheels();i++)
		{
			btWheelInfo& wheel = m_vehicle->getWheelInfo(i);
			wheel.m_suspensionStiffness = suspensionStiffness;
			wheel.m_wheelsDampingRelaxation = suspensionDamping;
			wheel.m_wheelsDampingCompression = suspensionCompression;
			wheel.m_frictionSlip = wheelFriction; //<----- setting the friction of the wheels
			wheel.m_rollInfluence = rollInfluence;
		}
with the constants being defined at lines 58 - 73 -

Code: Select all

const int maxProxies = 32766;
const int maxOverlap = 65535;

float	gEngineForce = 0.f;
float	gBreakingForce = 0.f;

float	maxEngineForce = 1000.f;//this should be engine/velocity dependent
float	maxBreakingForce = 100.f;

float	gVehicleSteering = 0.f;
float	steeringIncrement = 0.04f;
float	steeringClamp = 0.3f;
float	wheelRadius = 0.5f;
float	wheelWidth = 0.4f;
float	wheelFriction = 1000;//BT_LARGE_FLOAT; //<----- friction constant
float	suspensionStiffness = 20.f;
float	suspensionDamping = 2.3f;
float	suspensionCompression = 4.4f;
float	rollInfluence = 0.1f;//1.0f;
Brunni
Posts: 3
Joined: Sun Sep 09, 2012 10:55 pm

Re: Vehicle demo - no friction?

Post by Brunni »

Thank you for the answer, but unfortunately I tried that too and it doesn't change anything. :(
I think the default 1000 is already a quite big value and it should exhibit some friction in the AppVehicleDemo as the ground has 0.5, but there is no such thing all.
It looks like this parameter m_frictionSlip is only used to calculate the maximum impulse that will make the vehicle to "drift"... (at least if I can understand btRaycastVehicle::updateFriction)

Could someone take a look at this demo and tell whether it's normal that it has no friction?
Brunni
Posts: 3
Joined: Sun Sep 09, 2012 10:55 pm

Re: Vehicle demo - no friction?

Post by Brunni »

Ok, I figured out in another demo (ForkLiftDemo) that apparently you had to apply a constant "brake" to the engine to have friction. You should be able to obtain the brake factor to apply depending on the ground body found by raycasting (groundObject in btRaycastVehicle::updateFriction).

Now, I'm trying to do a proper simulation of a kart but the problem is that it is "jumping" (taking off) and loosing control even in a very small and long bump. If you look at games like Mario Kart, the kart is kept to the ground unless a tight bump is taken (big difference of angle between the previous segment and the next one).

Do you have any hint on how to model this physically? (stiffness of suspensions, etc.)

Thanks in advance! :)
fsxfreak
Posts: 10
Joined: Mon Sep 03, 2012 12:09 am

Re: Vehicle demo - no friction?

Post by fsxfreak »

You have the same problem I did when I first tried to implement a vehicle.
Here are my working parameters -

Code: Select all

btVector3 gravity(0, -100, 0); //so you can find relative values
int mass = 300;
btScalar suspensionRestLength(0.2f);
wheelinfo.m_suspensionStiffness = 75.f;
//from 0.0 (bouncy) - 1.0 (not bouncy)
float bounciness = 0.4f;
float damping = bounciness * 2.0f * btSqrt(wheelinfo.m_suspensionStiffness);
wheelinfo.m_wheelsDampingRelaxation = damping;
bounciness = 0.1f;
damping = bounciness * 2.0f * btSqrt(wheelinfo.m_suspensionStiffness);
wheelinfo.m_wheelsDampingCompression = damping;
wheelinfo.m_maxSuspensionTravelCm = 500.f;
wheelinfo.m_maxSuspensionForce = 5000000.f;
wheelinfo.m_frictionSlip = 0.8f;
wheelinfo.m_rollInfluence = 0.1f;
but what was really causing my vehicle to bounce like a ball on the moon was:

Code: Select all

mVehicle->updateVehicle(1);
instead of:

Code: Select all

mVehicle->updateVehicle(milliseconds / 1000);
Hope this helps.