This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

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

in Engine by (24 points)

2 Answers

+4 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 (22,191 points)

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

+1 vote

You can do:

var choice = randi() % 2 == 0
by (16 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 Frequently asked questions and 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 [email protected] with your username.