Skip to content

Instantly share code, notes, and snippets.

@grapefrukt
Created April 19, 2018 19:54
Show Gist options
  • Save grapefrukt/51b64965fb65494790038013c5a12bc7 to your computer and use it in GitHub Desktop.
Save grapefrukt/51b64965fb65494790038013c5a12bc7 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Wave : MonoBehaviour {
public float stayLow = 2f;
public float stayHigh = 2f;
private void OnDrawGizmos() {
var p0 = Vector2.zero;
for (var i = 0; i < 400; i++) {
var p1 = new Vector2(i / 20f, Curve(i / 20f, stayLow, stayHigh));
Gizmos.DrawLine(p0, p1);
Gizmos.DrawSphere(p1, .1f);
p0 = p1;
}
}
static float Curve(float t, float stayLow, float stayHigh) {
var zeroToOne = Mathf.Clamp01(Mathf.PingPong(t, 1 + stayHigh + stayLow) - stayLow);
// replace with any easing function that accepts 0-1 as input
return easeOutQuad(zeroToOne);
}
public static float easeInOutQuad(float t) {
if (t < 0.5f) return 2 * t * t;
return (-2 * t * t) + (4 * t) - 1;
}
public static float easeInQuad(float t) {
return t * t;
}
public static float easeOutQuad(float t) {
return -(t * (t - 2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment