How do I can set spawn objects randomly BUT NOT densely?

Get help using Construct 2

Post » Tue Jun 28, 2016 9:09 pm

I want to spawn 50 trees on my layout but i want to do, that every tree will be away from another a specified minimum distance (not too densely).
Can you help me?
B
5
Posts: 12
Reputation: 249

Post » Tue Jun 28, 2016 10:01 pm

Run a loop with a variable counter 50
While counter > 0

Pick random spot

If spot is NOT within minimum of distance of tree - Place tree at spot, reduce counter by 1

(if it is too close to a placed tree, the event will run again without reducing the counter and pick a new spot to try)

Edit: Depending on the availability of space for placement, this can be a very inefficient method. If there is not much space left for that last tree, it might loop a ton of times before randomly hitting that spot.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Wed Jun 29, 2016 8:47 am

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 29, 2016 10:30 am

Is working with a grid an option for you? Say you place a tree every 100 pixels and only randomize a limited offset to that regular interval
B
12
S
5
Posts: 216
Reputation: 1,692

Post » Thu Jun 30, 2016 5:54 pm

We had an issue like this with galaxy generation. I fixed it similar to @facecrime 's solution, by generating random whole numbers, back checking versus existing numbers then spacing it via a preset limit (like padding 0.3 of 1 unit of space) to prevent crowding.
Last edited by gumshoe2029 on Fri Jul 01, 2016 3:04 pm, edited 1 time in total.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Thu Jun 30, 2016 9:34 pm

B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455


Return to How do I....?

Who is online

Users browsing this forum: plinkie, Yahoo [Bot] and 19 guests