## How to compute Lateral Friction Direction ?

Please don't post Bullet support questions here, use the above forums instead.
Jack2016
Posts: 10
Joined: Fri Aug 12, 2016 5:46 am

### How to compute Lateral Friction Direction ?

After compute the Jacobian of contact point constraint,
I compute the Jacobian of friction ,I have to compute the friction Direction Dk whick store in cp.m_lateralFrictionDir1.
But it's not clear about why compute this way below

Code: Select all

``````btVector3 tbRigidBody::getVelocityInLocalPoint(const btVector3& rel_pos) const
{
//we also calculate lin/ang velocity for kinematic objects
return m_linearVelocity + m_angularVelocity.cross(rel_pos);

//for kinematic objects, we could also use use:
//		return 	(m_worldTransform(rel_pos) - m_interpolationWorldTransform(rel_pos)) / m_kinematicTimeStep;
}
/////setup the friction constraints
btVector3 vel1 = rb0 ? rb0->getVelocityInLocalPoint(rel_pos1) : btVector3(0,0,0);
btVector3 vel2 = rb1 ? rb1->getVelocityInLocalPoint(rel_pos2) : btVector3(0,0,0);

vel  = vel1 - vel2;

rel_vel = cp.m_normalWorldOnB.dot(vel);

{
btVector3 frictionDir1 = vel - cp.m_normalWorldOnB * rel_vel;
btScalar lat_rel_vel = frictionDir1.length2();
if (lat_rel_vel > SIMD_EPSILON)//0.0f)
{
//use projected normal direction as first friction direction and cross product of normal and frictionDir1 as second friction direction
frictionDir1 /= btSqrt(lat_rel_vel);
btVector3 frictionDir2 = frictionDir1.cross(cp.m_normalWorldOnB);
frictionDir2.normalize();
} else
{
//calculate two orthogonal vectors to normal direction
//re-calculate friction direction every frame, todo: check if this is really needed
btVector3   frictionDir1,frictionDir2;
btPlaneSpace1(cp.m_normalWorldOnB,frictionDir1,frictionDir2);
}

}

``````
bone
Posts: 235
Joined: Tue Feb 20, 2007 4:56 pm

### Re: How to compute Lateral Friction Direction ?

Because friction is modeled as two semi-independent constraints (to model the 2 degrees of freedom on a 2-D surface), it's not really being modeled as a friction circle. More like a friction square or friction diamond. Because of this, you can get artifacts where the overall friction force is not quite opposite of the direction of travel. This makes thing slide in a curve rather than a straight line, and can be quite noticeable.

In order to improve this behavior, you set the first friction direction as the direction of travel. You'll find that the resulting impulse in that direction is relatively large compared to the impulse in the perpendicular direction (which should be close to zero). This almost completely eliminates the artifact, at least visually.