0 votes

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?

Godot version 3.3
in Engine by (365 points)

1 Answer

0 votes

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!)

by (365 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.