Could someone please explain what exactly Mathf.Repeat and Mathf.PingPong do in a bit more detail than the docs? I'm just not quite getting it. thanx! d
Repeat is the same as the modulo operator. (Which btw. does work with floats.) Repeat(t, length) works a bit like this (for positive t): Code (csharp): if t is less than length, return t unmodified. if t is greater than length, subtract length from t until t is less than length Example: Code (csharp): // Will print 0,1,2,0,1,2,0,1,2 foreach( var t in [0,1,2,3,4,5,6,7,8]) { print(Mathf.Repeat(t, 3)); } PingPong will reverse the interval on every second repeat. Code (csharp): // Will print 0,1,2,3,2,1,0,1,2 foreach( var t in [0,1,2,3,4,5,6,7,8]) { print(Mathf.PingPong(t, 3)); } PingPong could actually be implemented using Repeat like this: Code (csharp): function MyPingPong(t, length) { var result=Mathf.Repeat(t, length*2); if( result > length) result = (2*length) - result; return result; }
Thanx for that exlpanation. Now I understand the .mov texture animation script i've been using. Still not so sure I understand Mathf.PingPong or what you'd use that for, though. thanx again! d
If you used Repeat in the mov script to loop an animation, using PingPong would let it play backwards and forwards instead.
Oh, i get it! Really had to hit me over the head with that one! That's really cool to have a built-in function that does that.