Randomly placing non-overlapping nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By devAS

Hello, I’m new to your engine and am working on my first game. In it the player can only move forward or backward(towards right or left on screen). So for this I need that as the player keeps moving forward, he keeps getting more and more nodes ( which are just StaticBody2D nodes player can land and move/jump forward on ). Also, These new progressing nodes should be non overlapping and if possible at a certain minimum distance.

It’s in 2D only.

So, to sum up I want somewhat:

  1. Random placing of nodes as player moves forward.
  2. Non-overlapping
  3. Infinite

EDIT: Is this (or somewhat like this) is what is called procedural generation?

Please suggest me some ways or code snippets to do the above mentioned.
Thanks in Advance for spending your precious time in helping me out in my problem

:bust_in_silhouette: Reply From: devAS

I solved it myself after several days when no one replied. :\

please share your result

gieyan | 2021-12-05 18:20

Basically what you do is…
Create a RandomNumberGenerator and then you use the generated numbers according to your specific needs.

In my case, I assigned the randomly generated number to co-ordinates of pixels on screen and to maintain a certain distance between the nodes, I checked if every next generated number was at least that(the certain distance) much greater than the last one, if not you generate again, or simply add the remaining distance needed to achieve the separation, which has to be calculated for every node.

You can see this example in play in my project here: Test Project/ Bunny Maniac by Anurag Singh

devAS | 2021-12-09 06:38