Original Post
I am creating a simulation of a sphere (ball) bouncing on a plane, then rolling until it stops. However, I am having dificulty having the sphere actually stop due to friction. I believe it is because of my unstable friction state, however, I will post all of my details case I am wrong.
1) Check sphere and plane collision
If there was no collision
Compute total force -> ball.TotalForces = ball.force + ball.weight + ball.dragForce
Compute acceleration -> ball.linearAcceleration = ball.TotalForces / ball.mass
Compute the velocity -> ball.linearVelocity = ball.linearVelocity + ball.linearAcceleration * dt
If there was collision
Compute linear velocity after contact -> ball.linearVelocity = -ball.coefficientOfRestitution * ball.normalVelocity + ball.tangentialVelocity
Up to this point it has been rather generic, this is basically just general physics. It is when I have resting contact that I am not slowing down the force. The force that I need to be slowing down is ball.force, which is initially set to (100, 400, 0)
If there was resting contact
Check to see if it is in stable static state -> If ball.linearVelocity.Norm == 0
Calculate static friction -> staticFriction = ball.StaticFrictionCoefficient * ball.normalForce.Norm * plane.normal.normalize
Set the friction force to static friction -> ball.frictionForce = staticFriction
Set the linear velocity to zero -> ball.linearVelocity = (0, 0, 0)
Set the linear acceleration to zero -> ball.linearAcceleration = (0, 0, 0)
Compute the total force applied to the ball -> ball.TotalForces = ball.weight + ball.normalForce
Check to see if it is in dynamic state -> if ball.linearVelocity.Norm > 0 && force.norm >= staticFriction.norm
Compute Kinetic friction -> kineticFriction = -ball.DynamicFrictionCoefficient * ball.normalForce.norm * linearVelocity.normalize
Set the friction force to kineticFriction -> ball.frictionForce = kineticFriction
Compute the total force -> ball.totalForces = ball.force + ball.weight + ball.normalForce + ball.frictionForce + ball.dragForce
Compute the linear acceleration of the ball -> ball.linearAcceleration = ball.Totalforces / ball.mass
Compute the linear velocity of the ball -> ball.linearVelocity = ball.linearVelocity + ball.linearAcceleration * dt;
Check to see if it is in unstable state -> if ball.linearVelocity.Norm == 0 && ball.force.norm > staticFriction.norm
Compute static friction in the opposite direction of the contact normal(***) -> staticFriction = -ball.StaticFrictionCoefficient * ball.normalForce.Norm * plane.normal.normalize
Compute the sliding factor to make the transition from static to dynamic friction state -> slidingFactor = ball.force.norm / ball.frictionForce.norm
Compute a small velocity to break the transition from static friction to dynamic friction -> ball.linearVelocity = slidingFactor * ball.force.normalize
Compute kinetic friction -> ball.frictionForce = -ball.DynamicFrictionCoefficient * ball.force.norm * ball.linearVelocity
Compute the total forces on the ball -> ball.totalForces = ball.force + ball.weight + ball.normalForce + ball.frictionForce + ball.dragForce
Compute the linear acceleration -> ball.linearAcceleration = ball.totalForces / ball.mass
Compute the linear velocity = ball.linearVelocity = ball.linearVelocity + ball.linearAcceleration * dt
After all of the collision reponses are done, I will just pdate the ball
2) Update the ball
ball.speed = ball.linearVelocity.norm
ball.dragForce = -.5f * ball.rho * ball.speed * ball.dragCoefficient * ball.area * ball.linearVelocity
ball.position = ball.position + ball.linearVelocity * dt
One thing I notice is that the first calculate in the unstable state is of static friction (marked with the ***). I was unable to find a calculate that actually applies that static friction, even though I know it is required to be calulcated in that state. The other problem I ran into is that just ball.force never gets changed, yet that is that applied force. How can I have the ball.force slow down, am I applying a calculation wrong? I have posted about this in the past, but my question and details were unclear so I figured I would make a new post.