Xnapoolfriction

Adding friction to the ball is pretty simple. If you multiply the current speed of the ball by a scaling factor during the update method you will eventually bring the ball to a crawling stop. The trouble with doing this usualy means that the ball can still be moving, althought it is visually non-moving, due to the fact that the speed will never hit zero. It's advisable that you record at which speed the ball no longer moves visually and you set it to the value of zero.

// The required variables
float frictionFactor = 0.05f;
float ballSpeed = 10.0f;
 
// Slow the ball down
ballSpeed *= frictionFactor;

Note: The friction factor is not exact, figure it out through trial and error.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.