How to set created object Y position in sets of 50 pixels?

Get help using Construct 2

Post » Thu Mar 17, 2016 3:46 pm

I've got a block thats created every second, and have it randomise the Y position everytime it's created. I know how to randomise that block, i've got that working fine but i wanted so that when it randomises, it does it in sets of 50 pixels (hope that made sense).

So if my layout height is 300, how do i get my created block Y position to appear randomly in either 0, 50, 100, 150 etc. rather than just any random number between 0,300?

I hope I've worded this correctly so it's easy to understand what i'm asking, hope seomeone can help.

Thanks.
B
5
S
2
Posts: 116
Reputation: 867

Post » Thu Mar 17, 2016 4:07 pm

Something like this?

1- Divide your height by your desired width: 300 / 50 = 6
2- floor(random(6)) = your random location
3- your Y value = 50 * random from step 2

Example:
300 / 50 = 6
floor(random(6)) = 2
50 * 2 = 100 <--- Answer

Have fun!
B
33
S
10
G
4
Posts: 51
Reputation: 3,499

Post » Fri Mar 18, 2016 11:56 am

@broknecho Thanks for the reply, but thats just got me confused :)

How would i input this into my events?
B
5
S
2
Posts: 116
Reputation: 867

Post » Fri Mar 18, 2016 12:53 pm

Think of it more like a grid. What your randomizing is a chosen cell in that grid. For example, randomize a round number from 0-10 then x it by 50. It would look something like this round(random(10))*50. That's if my maths is correct anyway.
Need help finding the right look for your game? I can help! hayes2D.com
B
28
S
5
Posts: 177
Reputation: 2,128

Post » Fri Mar 18, 2016 2:16 pm

ImageImage
B
111
S
51
G
24
Posts: 787
Reputation: 23,394

Post » Fri Mar 18, 2016 2:40 pm

Sorry about that @SteveKane! I thought you were more just looking for the pseudo code or math to do it.

@alextro 's capx works good! Here's a screenshot of their solution on the the math there:

Image

That capx creates that green sprite on a multiple of 50 in the X axis along the top of the screen, Guitar hero-esque :)
B
33
S
10
G
4
Posts: 51
Reputation: 3,499

Post » Fri Mar 18, 2016 4:34 pm

@broknecho @alextro @0Hayes Thanks for the replies, really helped me out. Appriciate it :)
B
5
S
2
Posts: 116
Reputation: 867


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 51 guests