No friction perpendicular to m_lateralFrictionDir1 when using custom contactAddedCallback

Lyhed
Posts: 2
Joined: Mon Dec 23, 2019 12:14 pm

No friction perpendicular to m_lateralFrictionDir1 when using custom contactAddedCallback

Post by Lyhed »

I'm trying to create a conveyor belt-like effect in Godot, which uses Bullet 3, but I'm unsure which minor version. I have a static body as a floor, and a rigid body which should slide along this floor towards -z. I've been searching around the forum and this solution keeps coming up. The answer is a bit outdated as m_lateralFrictionInitialized is still a bool, so I'm thinking there might be something else that has been updated which breaks the answer...

My contactAddedCallback looks like this:

Code: Select all

CollisionObjectBullet* obj0 = (CollisionObjectBullet*)colObj0Wrap->m_collisionObject->getUserPointer();
if(obj0->is_static()) {
	cp.m_contactPointFlags |= BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED;
	cp.m_lateralFrictionDir1.setValue(0.0, 0.0, -1.0);
	cp.m_lateralFrictionDir1.normalize();
	cp.m_lateralFrictionDir2.setValue(1.0, 0.0, 0.0);
	cp.m_contactMotion1 = 1.0f;
}
And I've set m_solverMode to include SOLVER_ENABLE_FRICTION_DIRECTION_CACHING.

The issue is that there seems to be no friction along m_laterialDrictionDir2, as my rigid body with an initial velocity of (1, 0, 0) just keeps sliding along the x-axis when it touches the ground, though it does start moving along the z-axis as well - as expected.

Like I said I use Godot, but I have addded some slight modifications to the source code. If anyone wants to try this out for themselves I can send the Godot scene file and list my (very few) changes.

Does anyone have any idea why there is no friction?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: No friction perpendicular to m_lateralFrictionDir1 when using custom contactAddedCallback

Post by drleviathan »

The alternate solution as mentioned in the linked thread is to give the conveyor a non-zero velocity in the direction you want it to convey. No callback complexity required, however this solution requires the conveyor be either static or kinematic but not dynamic. In this scenario the conveyor is not integrated forward by Bullet (static would have no integration at all and kinematic would require explicit integration by custom code), but on collision its non-zero velocity imparts momentum to dynamic objects.

An advantage of making the conveyor kinematic is you can flag it to always be "active" which will prevent dynamic objects from being deactivated accidentally while on the conveyor (e.g. should they be temporarily be blocked and nearly at rest for more than 2 seconds).

Dial the coefficient of friction on the conveyor and/or dynamic objects to tune how fast the perpendicular components of velocity are damped out. You might also want to give the conveyor a zero coefficient of restitution to reduce bouncing.
Lyhed
Posts: 2
Joined: Mon Dec 23, 2019 12:14 pm

Re: No friction perpendicular to m_lateralFrictionDir1 when using custom contactAddedCallback

Post by Lyhed »

Unfortunately the reason I chose to do it with a callback is because setting a linear velocity for static objects does not work in the current version of Godot, as this issue describes. Though perhaps it does not work for the same reason my custom callback doesn't...
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: No friction perpendicular to m_lateralFrictionDir1 when using custom contactAddedCallback

Post by drleviathan »

It should work for kinematic objects. You would want a kinematic object with non-zero velocity but whose position never actually changes. I dunno Godot but perhaps it has a way to do that.