gContactAddedCallback and vehicle friction

hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

gContactAddedCallback and vehicle friction

Post by hiker »

Hi all,

I've been trying to use per-triangle friction for a btRaycastVehicle using the gContactAddedCallback. I noticed a few problems I don't fully understand:
  • 1) It appears that this callback is not called in every timestep - esp. when I am not accelerating this callback appears not to be called. But (I was always using this callback to detect when the vehicle is on an invalid texture like water and need to be 'rescued') in some cases even when accelerating I don't get the feedback (and the vehicle drives happily on the ocean :) ). Guess I have to do a separate raytest to trigger a rescue reliably.

    2) After setting the friction in cp.m_combinedFriction in my gContctCallback function (cp being the btManifoldPoint) I don't see any difference in the behaviour of the kart. Even when returning 0 as friction (which I would assume would make the kart either skid, or not accelerate anymore?) I didn't notice any difference in the vehicle's behaviour. What do I have to do to set the friction for a vehicle - change the parameter of the wheel?
Cheers,
Joerg
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: gContactAddedCallback and vehicle friction

Post by Erwin Coumans »

The raycast vehicle uses a raycast to determine contact with the ground, so it will not use the regular collision detection (and hence no gContactAddedCallback, if you get gContactAddedCallback calls it means the chassis is touching the environment).

Please check and modify the following method in Bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp:

Code: Select all

void	btRaycastVehicle::updateFriction(btScalar	timeStep). 
I just made 'updateFriction' a virtual method, so you can customize the friction model in your derived class.

Hope this helps,
Erwin
hiker
Posts: 83
Joined: Tue Oct 24, 2006 11:52 pm
Location: Australia

Re: gContactAddedCallback and vehicle friction

Post by hiker »

Hi Erwin,
Erwin Coumans wrote:The raycast vehicle uses a raycast to determine contact with the ground, so it will not use the regular collision detection (and hence no gContactAddedCallback, if you get gContactAddedCallback calls it means the chassis is touching the environment).
Ah - that would explain what I see, and means that I can remove all of this gContactAddedCallback handling :( .
Please check and modify the following method in Bullet/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp:

Code: Select all

void	btRaycastVehicle::updateFriction(btScalar	timeStep). 
I just made 'updateFriction' a virtual method, so you can customize the friction model in your derived class.
I had a quick look, it appears to be a lot of work. Without really studying all of the code, I guess I'd have to:
  • write a new castRay plus result structure, since the triangle index information is lost somewhere from the AddSingleResult call in the rayTest to the castRay call of the vehicle. I don't want to have separate bodies for each material (which would be easier to handle otherwise, since this information is available in m_groundObject), since in my case I end up with many bodies for the actual track: e.g. there would be road, road_grass, grass, grass_beach, beach for a track with a road, some grass on the side before beach is coming - meaning 5 bodies to test instead of one. That would add (I guess) some unnecessary overhead for rayTesting, collision detection etc.(?)
  • understand updateFriction :oops: and rewrite it
Would it be possible to add a more convenient interface for this problem to bullet? After all, I would suspect that most programs using the raycast vehicle will face this problem sooner or later. This is not an urgent issue for me at the moment, since skidding is currently being scheduled for the release after the next (I was rather surprised how easy it was to add friction when I looked at the gContactAddedCallback, which I though would solve my 'when to trigger automatic rescue' problem ... which it is not :) ).

As a side note, after a very quick glance at the code in updateFriction:

Code: Select all

btScalar maximp = wheelInfo.m_wheelsSuspensionForce * timeStep * wheelInfo.m_frictionSlip
...
if (impulseSquared > maximpSquared)
{
    sliding = true;
    btScalar factor = maximp / btSqrt(impulseSquared);
...
    m_wheelInfo[wheel].m_skidInfo *= factor;

}
Wouldn't it be enough if I modified the wheelInfo.m_frictionSlip in each timestep to get the desired effect (i.e. skidding)?

Thanks for your quick answer!
Joerg