+1 vote

I want to generate a random boolean to select random direction of rotation (for an asteroid if you're interested :) )

in Engine by (23 points)

1 Answer

+3 votes

You could do something like this:

var dir = true
if randi() % 2:
    dir = false    

On the other hand, if you're looking for a random rotation direction, then what you really want is either 1 or -1, which you can get if you raise -1 to a random power of 0 or 1.

var random_dir = pow(-1, randi() % 2)
by (20,923 points)

Or (randi() & 2) - 1, if you need either -1 or 1.
If you only need 0 or 1, just randi() & 1.

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.