How do I set position of item, randomly within a range?

Get help using Construct 2

Post » Mon Jan 18, 2016 11:12 pm

https://www.dropbox.com/s/tnnrbesnh5irj ... .capx?dl=0 - I am working on the mechanics of a simple running platformer game, however have a small issue which I cannot figure out. In step9, the y-coordinate of the block is set at random(LayoutHeight - self.height). Is there a way to change that to depend on the previous y-coordinate of the block? example can only be 100px above or below previous position?
B
5
Posts: 36
Reputation: 301

Post » Tue Jan 19, 2016 3:05 am

You would need to store the previous position.Y in a variable and then use the < and > in condition for next spawn...
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370

Post » Wed Jan 20, 2016 2:28 pm

Can you explain the second part further, I have stored the y position as a global variable. However I don't know how to do the second part.
B
5
Posts: 36
Reputation: 301

Post » Wed Jan 20, 2016 2:33 pm

I guess instead of:

random(LayoutHeight - self.height)

You'd use

random(Oldposition-100,Oldposition+100)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jan 20, 2016 2:38 pm

Thanks a lot :) For some reason I thought random values can only be between 0 and another number.
B
5
Posts: 36
Reputation: 301

Post » Wed Jan 20, 2016 4:34 pm

You have to remember the variable is holding a number value in this case so it can be randomized as well.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
66
S
17
G
8
Posts: 637
Reputation: 9,370


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 25 guests