Function lerp_angle
pub fn lerp_angle(from: f64, to: f64, weight: f64) -> f64Expand description
Linearly interpolates between two angles (in radians) by a weight value between 0.0 and 1.0.
Similar to [method lerp], but interpolates correctly when the angles wrap around @GDScript.TAU. To perform eased interpolation with [method lerp_angle], combine it with [method ease] or [method smoothstep].
extends Sprite
var elapsed = 0.0
func _process(delta):
var min_angle = deg_to_rad(0.0)
var max_angle = deg_to_rad(90.0)
rotation = lerp_angle(min_angle, max_angle, elapsed)
elapsed += deltaNote: This function lerps through the shortest path between from and to. However, when these two angles are approximately PI + k * TAU apart for any integer k, it’s not obvious which way they lerp due to floating-point precision errors. For example, lerp_angle(0, PI, weight) lerps counter-clockwise, while lerp_angle(0, PI + 5 * TAU, weight) lerps clockwise.