- Home /
Math help - sinus graph
Hello
I am trying to make a mathematic formula, which if multiplied by a continuisly increasing variable (this case Time.deltaTime) it will produce a sinus-graph like value increase: like it starts increasing slowly, than it reaches full speed, than it starts to decrease slowly;kind of like watertides licking the beach sand.
I lack the necessary knowledge with sin,cos and radians ,so if you could help me out, that would be greatly appriciated.
Thanks!
Answer by Berenger · Mar 02, 2012 at 07:59 PM
First, Time.deltaTime isn't constantly increasing as it is the time past since the last frame. It's usually under 0,1. You're talking about Time.time, the time past since the begin (scaled by timeScale).
Now, to do what you're talking about, just write
fx = Mathf.Abs( Mathf.Sin( Time.time * Mathf.PI * speed ) ) * amplitude;
That way, fx will vary between 0 and amplitude in one second *speed. Alternatively, take a look at Mathf.Repeat (//////) and Mathf.PingPong (/\/\/\/\/) instead of the trigo functions (/¯_ /¯_/¯).
Finally, if you want a better control over all those things, there is the AnimationCurve class, which isn't that hard to use.
Yes, thanks you very much ,that is almost exactly what i needed, it still doesnt go into negative,like i wanted it to ,but its a great start. Also, i will look into those other methods you linked. Again ,thanks a lot!
Oh, I thought you didn't want negative, oups. Get rid of the Abs then