How do I add random pos

Get help using Construct 2

Post » Fri Oct 24, 2014 12:34 pm

Hi i need to create an object every second who fall, i have done that, but i need to make my blue object to be created at just 3 positions, on the red, on the orange and onthe yellow position, but randomised, how to do that??

Image
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612

Post » Fri Oct 24, 2014 12:43 pm

You can use "choose"

For example: spawn object at postition y: value x: choose(value1,value2, value3)

So the system will choose one of the three values of the X-axis and the order will be random.

So the y-axis value is always the same
B
54
S
23
G
13
Posts: 751
Reputation: 12,418

Post » Fri Oct 24, 2014 12:48 pm

whats the correct formula to use?? :D
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612

Post » Fri Oct 24, 2014 12:57 pm

What do you mean? :) If you want to create an object at the position y: 100 and random x: 100 or 200 or 300 you can do it like this:

every 1 seconds - system - create object at position y: 100 x: choose(100, 200, 300)

From the manual:

choose(a, b [, c...])

Choose one of the given parameters at random. E.g. choose(1, 3, 9, 20) randomly picks one of the four numbers and returns that. This also works with strings, e.g. choose("Hello", "Hi") returns either Hello or Hi. Any number of parameters can be used as long as there are at least two.
B
54
S
23
G
13
Posts: 751
Reputation: 12,418

Post » Fri Oct 24, 2014 1:10 pm

i used random(pos1.X,pos2.X,pos3.X) but its wrong :s
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612

Post » Fri Oct 24, 2014 1:27 pm

Try to replace "random" with "choose" instead and only use the number values. Not 100.x, 200.x, 300.x just 100, 200, 300.

So create object at:

Y: 100
X: choose(100, 200, 300)

And replace those values with the correct y and x values you want.

Hard to explain. Can be more specific when I'm home from work :P
B
54
S
23
G
13
Posts: 751
Reputation: 12,418

Post » Fri Oct 24, 2014 1:42 pm

Oki i found :p :D thanks again :D
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612

Post » Fri Oct 24, 2014 1:45 pm

Great, good luck with your project :D
B
54
S
23
G
13
Posts: 751
Reputation: 12,418

Post » Fri Oct 24, 2014 2:13 pm

Well :D now i have another problem, the object is falling at randomized 3 positions, but the speed is not constant :s how to make the fallings object to allways have the same speed?

my object has a platform movement :s
B
37
S
15
G
7
Posts: 1,680
Reputation: 9,612

Post » Fri Oct 24, 2014 3:47 pm

Try working with your platform settings.

gravity and max speed for starters... set your acceleration and deceleration to 0 as well...
B
11
S
2
Posts: 46
Reputation: 739

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, ChesVCF, OBLIVION, shinkan, Solomon, yiuyiu6666 and 23 guests