Random rotation both ways?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pferft

Hi everyone,

I built a random rotation tween for a sprite:

extends Sprite

func _ready():
	var tween = Tween.new()
	add_child(tween)
	
	tween.interpolate_property(self,"rotation_degrees",
	rotation_degrees, rand_range (0, 180), 1.5,
	Tween.TRANS_QUINT,Tween.EASE_IN)

	tween.start()
	
	yield(get_tree().create_timer(1.5),"timeout")
	queue_free()

This works, but the sprite only rotates clock-wise. I’d like it to randomly rotate clock-wise or counter-clock-wise. Could somehow a randomly chosen rand_range (0, -180) be added?

:bust_in_silhouette: Reply From: pferft

Oh my, (-180, 180) does the trick. In my mind the 0 made sure that the sprite will be orientated correctly before the animation starts, but of course that hasn’t anything to do with it. (Thanks for waking me up, FluffyRabbit on reddit!)