Randomizing between two angles

This forum is currently in read-only mode.
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • Hi, I'm trying to pick between two angles at random (-180 and 0), I don't wish to have any angles between these two just one or the other randomly picked. Could someone enlighten me on the correct syntax to achieve something like this?

    I've attached a link to a cap which demonstrates what I'm trying to achieve - when it's run it populates the ground area with a bunch of rectangles and randomizes their position and height, but they all face to a 0 degree angle and I would like to randomly alternate this between 0 and -180. Any help is much appreciated. Thanks!


  • Hey, Signal.

    Setting the rectangles' angles to

    180 + random(180)

    should give you an angle between 180 and 360, that is, between -180 and 0. I cannot yet load the cap you posted due to not having the latest Construct Classic, but I've made a similar model with my version, and it appears to work well enough.

    Hope I could be of help.

  • Hi, thanks for the reply :)

    If I set the rectangles angle to 180 + random(180) it still seems to pick any angles between those two values, whereas I just need it to be either -180 or 0 (ignoring all other angles), if you imagine the rectangles like skyscrapers, they all need to stand straight, but face either left or right, but at present with that code they randomize to all angles between those values. I'll see if I can track down and install an older version of cc and do up another example.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you need two random choices, start by not caring about the actual values. You need a random number that returns exactly one of two numbers. random(n) returns a number between 0 and n-1. So random(2) will return 0 or 1

    Now multiply that with the -180 and you get either 0 or -180 (0 * -180 = 0, 1 * -180 = -180

    The expression should look somewhat like that:

    random(2) * -180

    EDIT: I'd say, this thread better belongs to the help section ;)

  • Oops, I didn't realize I was in the discussion forum - I meant for this to go in help - too many tabs open! :P Anyway, thanks - random(2) * -180 worked a treat. Much appreciated.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)