Using Sine Wave to control time

hello!
i have my object that is moving in a sin wave with mathf function, that is this

float t = currentLerpTime / lerpTime;
t = Mathf.Sin(t * Mathf.PI * 0.5f);

i want something that start fast and finish slower so i think that the sine wave is what i’m looking for but i don’t really know how to manipulate it to get what i looking for… any help?

what i exactly want is something like this but without using AnimationCurve
alt text

You can change the amplitude and period of a sine wave. The following page shows you how to change the period: Adjusting the Period of a Sine Function - dummies
The amplitude of the sine wave is simple a multiplication of the outcome of the Sin calculation.


So as you show with the curve in the picture, you are looking for a logarithmic curve. Using the following formula will get you there: Vc = V * (1- e^(-t / R*C)).

  1. Vc = Value on the curve after t-seconds
  2. V = Maximum value of the graph (so 1.0)
  3. e = constant (2.71…)
  4. t = time in seconds
  5. R*C / TAU = not really important what it means but you can control the curve with it. If you enter 1 here the curve will take 5 seconds to go from 0% to 100%, if you enter 2 here it will take twice as long.

In C# this formula will be:

float maxValue = 1.0f;
float timer = 1.0f // This is a timer or counter or something
float tauValue = 1.0f;
float value = maxValue * (1 - Mathf.Pow( (float) Math.E, (-timer / tauValue));

//I couldn't find E in the Mathf class so I had to add the System namespace to have Math.E

//This will be the code making use of the Mathf.Exp() function suggested by Bunny83
  
float maxValue = 1.0f;
float timer = 1.0f // This is a timer or counter or something
float tauValue = 1.0f;
float value = maxValue * (1 - Mathf.Exp(-timer/tauValue));

Some examples:
R*C = 1
t=1        Vc=0.63
t=2        Vc=0.86
t=3        Vc=0.95
t=4        Vc=0.98
t=5        Vc=0.99

R*C = 2
t=1       Vc=0.39
t=2       Vc=0.63
t=3       Vc=0.77
t=4       Vc=0.86
t=5       Vc=0.91
t=6       Vc=0.95
t=7       Vc=0.96
t=8       Vc=0.98
t=9       Vc=0.98
t=10     Vc=0.99