Randomise X location

This forum is currently in read-only mode.
  • I'm trying to spawn clouds on my background at a random X location, where they will then fade in and out over 30 seconds before spawning again. The clouds always spawn in the exact same X position though. Here's what I have for the event:

    Every 30000 milliseconds

    System: Create object Cloud on layer "Clouds" at (random(1,3000), 790)

    Have I misunderstood how the random expression works? I thought that random(1,3000) would make the cloud spawn somewhere between 1 and 2999 on the X axis.

    Thanks for your time <img src="smileys/smiley12.gif" border="0" align="middle" />

  • The random function only need one argument(in this case the 3000.) If you want to create something betwen lets just say -50 and 50, you can do it like this:

    random(100)-50

  • Ahhhh, okay thanks! I have that event set up three times, for three different sections of my level (to keep clouds spread out, and stop a freak occurrence of them all spawning next to each other). So at the moment I have the three X positions as:

    1,3000

    3500,6500

    7000,10000

    So if the first one should just be random(3000), how would I calculate the others? The mathematic side of my brain leaves a lot to be desired, so I'm struggling to understand how to adapt your example of random(100)-50 <img src="smileys/smiley17.gif" border="0" align="middle" />

    EDIT: Does the -50 part mark the starting point, and the (100) mean how to much to go up to from there? So would my second event be random(3000)6500? I may be completely wrong here.

  • -Silver-

    random(3000) + 3500

    random(3000) + 7000

    You only have to randomize the differences.:)

    Edit: a quick example, look at the first one. You want to create a random between 3500 and 6500. If you do it like this: random(3000) + 3500, and the random returns 20, you will get 3520, if it returns 1500, you will get 5000, and so on.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Haha, thanks! I updated my reply with a guess, but as I expected, I was completely wrong <img src="smileys/smiley17.gif" border="0" align="middle" />

    Thanks Pecek, much appreciated <img src="smileys/smiley1.gif" border="0" align="middle" />

  • That's why the forum for. <img src="smileys/smiley1.gif" border="0" align="middle" />

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