Take normalized directional vectors for angles.
A vector 1,0 will be 0 deg, vector 0,1 will be 90deg.
Then lerp between these vectors and find the angle of the resulting vector.
There are easier solutions for this if you manually calculate the angle instead of lerping. Or if you want to lerp the rotation of something, there is quaternion slerp in gdscript.
I actually compute the angle myself, and it’s 2D so I don’t use quaternions. Converting back and forth in vectors could work but I’m sure there is a faster way.
You can use wrapf, wrap the difference in -PI to PI
func lerp_angle(from, to, weight):
var diff = wrapf(to - from, -PI, PI)
var i = lerp(from, from + diff, weight)
# Keep the result in 0..2*PI
i = wrapf(i, 0, 2*PI)
return i
func _ready():
for i in range(0, 10):
print(rad2deg(lerp_angle(deg2rad(270), deg2rad(20), i/10.0)))