Spawn an object randomly at specific position

Get help using Construct 2

Post » Sun Aug 05, 2012 3:10 pm

Where do u find random or floor?
B
4
Posts: 15
Reputation: 355

Post » Sun Aug 05, 2012 3:42 pm

Like this

SYSTEM - CREATE OBJECT(SHIP) at floor(random(0,640),random(0,480))

This will create the ship you want to spawn at any location across or down the screen. The (0,640) tells Construct to pick a random number from 0 to 640 (saying your screen is 640 across, you obv change that number if your screen is smaller or larger). The same for the Y coord.

When you get the section that you normally would just enter the X and Y coords of a created item you just type in what I wrote above. FLOOR and RANDOM are not something you can click to select, you must enter them manually.

When Construct creates a random number it's a floating point number so it would be something like 1.23 for example. That's no good to the coordinates so you use FLOOR to round the number down to the closest Integer. So 1.23 would round down to 1. Hope this helps.vandinz2012-08-05 15:45:06
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Sun Aug 05, 2012 6:30 pm

In other words, instead of entering a numerical value into your actions like,

X = 9

You replace it with,

X = random(0,640)

What this does is give you a random number with decimals between 0 and 640. However, this gives you decimals which you don't want.

So you FLOOR this value by making,

X = floor(random(0,640))

So this gives you an integer between 0 and 640.

In my previous post, I mentioned rolling a random number between 1 and 10. I wouldn't need to floor it, but you'd need to use random(0,10)

Since you're spawning these objects at the specific point, don't think you'll be needing to create an object at a random X,Y.

I'd set a DICE variable to random(0,10)
and check if that variable is below 1, if it is, spawn an object at the specific point.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Tue Aug 07, 2012 12:29 am

ok this might sound a bit nooby but how do u set a dice varible?
B
4
Posts: 15
Reputation: 355

Post » Tue Aug 07, 2012 1:44 am

At this point, you're better off doing the tutorials than asking around in the forums.
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Tue Aug 07, 2012 4:39 am

Yeap, I have to agree.
@Sail338r go read the manuals! There's a whole library worth reading, and It'll really kick start your time with C2.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Previous

Return to How do I....?

Who is online

Users browsing this forum: badmoodtaylor and 8 guests