-
What do you want to achieve?
I want to create a field generator to generate fields like in the game “Bee Swarm Simulator”. They always have the same layout and to achieve that, I am using the Perlin Noise Function. I also added weights, meaning hat if the Perlin Noise Number is in the range from 0 to 0.3, it generates Red Flowers, from 0.3 to 0.6 White Flowers and from 0.6 to 1 Blue Flowers. The range can be changed to adjust the amount of flowers in the field, at least that’s how it should work -
What is the issue?
The issue is that the results concentrate around 0.5. This is especially an issue with the weights system, because the Perlin Noise Numbers are not equally spaced between 0 and 1.
So in short: My problem is that instead of being equally spaced between 0 and 1, the Perlin Noise Numbers are concentrated near 0.5, which breaks the system and makes it impossible to add weights.
local function ChoooseFlower(Field)
local FieldSettings = Settings.FieldSettings[Field.Name]
local FlowerWeight_Blue = FieldSettings.BlueFlowerWeight
local FlowerWeight_White = FieldSettings.WhiteFlowerWeight
local FlowerWeight_Red = FieldSettings.RedFlowerWeight
-- All weights add up to 1
local Seed = 0.2143
local PN_Number = ((math.noise(FieldGenX, 0, Seed) + 1) / 2)
if PN_Number <= 0 or PN_Number >= 1 then
error("Perlin-Noise-Error --> PN_Number: "..PN_Number)
end
FieldGenX = FieldGenX + 1
if PN_Number <= FlowerWeight_Blue then
return FlowersPresets.Flower_Blue:Clone(), PN_Number
elseif PN_Number >= FlowerWeight_Blue and PN_Number <= FlowerWeight_Red then
return FlowersPresets.Flower_White:Clone() , PN_Number
elseif PN_Number >= FlowerWeight_Red then
return FlowersPresets.Flower_Red:Clone(), PN_Number
end
end