Tweening a rotation that goes past TAU or below 0

Godot Version

4.4-stable

Question

I am writing a tween function for a rotating turret in a 2d game. The turret is supposed to follow the mouse or get locked onto a target. All that works fine.

The issue is that when the turret loops past a full circle (TAU or 0) it will tween along the scale 0 - TAU. This means that if I am following something up past 360 degrees (to say, 15 degrees) the tween will interpolate from 360-15 instead of 360 to 375.

How do I get the tween to go past the max angle or below the min angle?

Are you using angles or radians to rotate?

Radians are safer to use.

You could use lerp_angle() within the MethodTweener.

	var tween: Tween = create_tween()
	tween.tween_method(
		func(value: float) -> void:
			rotation = lerp_angle(start_rotation, end_rotation, value),
		0.0,
		1.0,
		2.0
	)

It’s all radians in the end.

That did it! Thank you very much. I think this info should be added to the tween docs.

1 Like

You can add a comment to the Tween docs, maybe that’ll help someone :slight_smile:

Already done! :slight_smile:

1 Like