# random(360)

0 favourites
• 7 posts
• 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?

• Random(180,360)

• Random(180,360)

Unfortunately that still includes 270 degrees. Wish I could include images or URL's to show what I mean.

• For exact angles the simplest way would be int(choose(20,340))

Or more complicated int(random(1))=1 ?20 :340

• That solved it!

I used this line which chooses from 6 different angles for left and 6 for right.

``````int(choose(20,40,60,340,320,300,160,140,120,200,220,240))[/code:1fyzdppr]

Thank you very much.``````
• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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.

• 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.

• 7 posts