-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MathUtils.pingpong() #21091
Add MathUtils.pingpong() #21091
Conversation
It looks like the current implementation doesn't work as expected with negative numbers: MathUtils.pingPong( - 1.5 ); // - 1.5
MathUtils.pingPong( - 2.5 ); // - 0.5 |
@gkjohnson missed that, thanks for testing. It is fixed by using the I added the correct negative case to the unit test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same function also exists in Unity, see
https://docs.unity3d.com/ScriptReference/Mathf.PingPong.html
Reference implementation:
Thanks, I was aware, I put the unity link in the description. From the unity implementation, I renamed the parameter |
Sorry, did not realize that^^. I know the method from Unity and I think it's a useful addition to |
Maybe |
Sure, it makes sense. Done! |
Thanks! |
Related issue: -
Description
One function I find useful is the pingPong function. It alternates between two values, you can use it to alternate between two colors for example.
It also can be combined with the in-out eases from Robert Penner's Easing Functions to create a differently shaped alternating function.
Here is how the function looks like:
https://www.desmos.com/calculator/vcsjnyz7x4