- Home /
number that crease and decrease
is there a function/argument that keeps going from 1 to -1? and then from -1 to 1?
something like this:
0.0f, 0.1f, . . . 0.9f, 1.0f, 0.9f, 0.8f, 0.7f, . . . 0.1f, 0.0f, -0.1f, -0.2f, -0.3f, . . . -0.9f, -1.0f, -0.9f, -0.8f, . . . -0.1f, 0.0f, . . .
it's like a Lerp function
Answer by tanoshimi · Apr 07, 2015 at 06:55 PM
Yes. Mathf.PingPong.
Hello, in addition to tanoshimi's correct answer you may have a trouble about having negative values on pingpong since it won't never go below zero. So do this trick; value = $$anonymous$$atfh.PingPong(...,20) - 10; So if value is zero at the beginning now with the line above it will start from -10 and will go to 10.
yes, i've tried that argument $$anonymous$$athf.PingPong (0.5f*Time.deltaTime, 20f)-10f
but the value just keeps at -9.99 or -9.98
Answer by ozturkcompany · Apr 08, 2015 at 11:22 AM
Hello, Try this;
#pragma strict
private var i : float = 0;
private var j : float = 0;
function Update ()
{
j += 0.01;//Makes "i" value decrease and increase 0.01 each frame, you can change it to any number you want
i = Mathf.PingPong(j, 2) - 1;
print(i);
}
Mathf.PingPong(t, length); The "t" value must not be constant, that's why your variable keeps in some value.
Your answer
![](https://koobas.hobune.stream/wayback/20220613192446im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Finding center of a cube 1 Answer
what is Vector3.normalized? 1 Answer
one or several scripts - what's better? 1 Answer
C#, "object reference not set to an instance of an object" 3 Answers
This doesnt work,help? 1 Answer