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

0 favourites
• 7 posts
From the Asset Store
You think you can guess the character’s name?! Then let’s see how smart you are!
• 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.

• 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!

• broknecho Thanks for the reply, but thats just got me confused

How would i input this into my events?

• ## Try Construct 3

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

Construct 3 users don't see these ads
• 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.

• This is should what you expect: https://dl.dropboxusercontent.com/u/659 ... fifty.capx

• 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:

That capx creates that green sprite on a multiple of 50 in the X axis along the top of the screen, Guitar hero-esque

• broknecho alextro Thanks for the replies, really helped me out. Appriciate it

• 7 posts