# random(360)

Get help using Construct 2

### » Mon May 18, 2015 12:05 pm

Hi,

What I have now:
A ball spawning in the centre of the screen and I'm at the moment using random(360) to make it shoot in random directions with the bullet behaviour.

What I want to do:
I want to control the direction which random(360) won't allow. For example if the generated random number is around 90 or 270 it means that the ball shoots down or up, which I don't want. I want to direct the ball a bit more to the left and right.

How do I go around this and solve the issue?
Last edited by Mr X on Mon May 18, 2015 12:25 pm, edited 2 times in total.
B
7
S
1
Posts: 37
Reputation: 509

### » Mon May 18, 2015 12:17 pm

Random(180,360)
B
173
S
50
G
195
Posts: 8,570
Reputation: 121,876

### » Mon May 18, 2015 12:22 pm

newt wrote:Random(180,360)

Unfortunately that still includes 270 degrees. Wish I could include images or URL's to show what I mean.
B
7
S
1
Posts: 37
Reputation: 509

### » Mon May 18, 2015 12:25 pm

For exact angles the simplest way would be int(choose(20,340))
Or more complicated int(random(1))=1 ?20 :340
B
173
S
50
G
195
Posts: 8,570
Reputation: 121,876

### » Mon May 18, 2015 12:45 pm

That solved it!

I used this line which chooses from 6 different angles for left and 6 for right.
Code: Select all
`int(choose(20,40,60,340,320,300,160,140,120,200,220,240))`

Thank you very much.
B
7
S
1
Posts: 37
Reputation: 509

### » Mon May 18, 2015 4:45 pm

You could also do something like this:
choose(0,180)+random(-1,1)*45

If 45 is two wide reduce it to a smaller number.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Mon May 18, 2015 5:26 pm

Awesome! That was exactly what I initially had in mind. Tested it and it worked like a charm. Thanks both of you for your responses and solutions.
B
7
S
1
Posts: 37
Reputation: 509