Is there something like unity's Mathf.pingpong available in godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KainAlive

I am switching from Unity to Godot and wanted to restart one of my Unity projects in Godot. This requires a “ping-pong” of the rotation value, so my player is rotating back and forth. In Unity I could use the Mathf.pingpong function. Is there any way to use something like this in Godot?

:bust_in_silhouette: Reply From: Juxxec

Check out this: Unity Forums | what exactly does Time.time do in Mathf.pingpong

You can use the information there to implement a utility method that does the same in Godot.

:bust_in_silhouette: Reply From: fergicide

This will pingpong a value between zero and one, scaled by amplitude. The sine function returns a value between -1.0 and 1.0 which is then converted to the range 0.0 to 1.0

value = (sin(time) + 1.0) * 0.5 * amplitude