language: C# (mono-2.8)
date: 527 days 2 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
 
namespace FrictionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            const float friction = 0.95f;
            const int frames = 60;
 
            float value = 1000f;
            Console.WriteLine(ApplyFriction(value, friction));
            
            for (int i = 0; i < frames; i++)
                value = ApplyFriction(value, friction, 1f / frames);
            Console.WriteLine(value);
        }
 
        static float ApplyFriction(float value, float friction)
        {
            return value * friction;
        }
 
        static float ApplyFriction(float value, float friction, float dt)
        {
            return value - value  * (1f - friction) * dt;
        }
    }
}