Skip to content

Instantly share code, notes, and snippets.

@EIREXE
Created October 12, 2019 19:32
Show Gist options
  • Save EIREXE/f5de8336fb4eaa9534b7d388b76a67a6 to your computer and use it in GitHub Desktop.
Save EIREXE/f5de8336fb4eaa9534b7d388b76a67a6 to your computer and use it in GitHub Desktop.
# Interpolates from a to b along a sine wave
func sin_pos_interp(from: Vector2, to: Vector2, amplitude: float, frequency: float, value: float) -> Vector2:
var dist = (from - to).length()
value = clamp(value, 0, 1)
if dist != 0:
var t = value * dist
var x = t
var angle = from.angle_to_point(to)
var y = amplitude * sin((t/dist)*PI*frequency)
var xp = (x * cos(angle)) - (y * sin(angle))
var yp = (x * sin(angle)) + (y * cos(angle))
return from-Vector2(xp, yp)
else:
return to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment