"Randomization tips"

Hello! I’m new to programming and Unity, and I’m working on a project, and I got to something I really hate doing.
Long story short, the camera keeps advancing and the character constantly loses health, and to regenerate it, it has to stay near some objects randomly spawned around the map
The thing is, that, of course, it cannot be completely random so the game doesn’t troll you. So the only thing I can think of is do some maths with speeds and time and so on and so forth to set some parameters for the random method.
Is there any tips I could use to make this easier instead of doing it the long way, so there aren’t too many so it is too easy and not too little so you die because of bad luck.
Thank you for your time and help.

I don’t understand this statement. Is your game sentient? :slight_smile:

If you mean you don’t want “really bad positions” coming up randomly, that’s something that you can address in a bunch of ways.

  1. set criteria for spawning position choice, i.e., “spawn only within X distance of me”

  2. choose completely randomly, but choose perhaps 10 candidate locations and then pick the one nearest (or best?) for the player.

check also voronoi and other random procedural generation algorithms.

First I would

  • find the maximum time to have between two points,
  • deduce the maximum distance with the speed,
  • add some padding for adjustment time.
  • Now divide this distance in two, this give you an interval,
  • take the center of that interval
  • and then spawn objects as an offset of that center such as offset < Interval/2.

The logique:
If offset = half the interval, it can effectively cover the entire range of the interval, which mean that maximum possible distance between two points is the maximum distance allowed you have find, and the closest distance is 0.

It allow you to effectively control difficult and randomness as you please, by reducing interval you make it easier, by controlling offset side you control randomness of minimal and maximal distance, with 0 offset (or non random offset) mean a very regular pattern. It also allow you to change difficulty over time or any other variable, effectively, you can increase or decrease these parameters according to other concern, for example creating a difficulty curve where interval progressively increase until they reach the theoretical limit, change based on distance to base, or change based on a difficulty biome, whatever you decide.