Hi there,
Because my question was bad worded, I tried to write it better.
I hope that everybody will understand it:
I am trying to make a procedural world and i wanted to spawn cubes with a random height so I took the position and added the seed, this was the new seed but the cubes weren’t randomly placed they looked like stairs because I can’t find the error I made, I am asking you if you could help me.
Here ist the .h file
UPROPERTY(EditDefaultsOnly)
int32 iSeed = 11110;
float GetNoise(int x, int y);
UPROPERTY(EditDefaultsOnly, Category = SpawnBlock)
TSubclassOf<class ABlock> BlockClass;
FRandomStream RandomStream;
This is the .cpp file:
void ARandomWorldGenerator::GenerateTerrain()
{
if (BlockClass)
{
FVector2D vActorLocation = FVector2D(GetActorLocation().X, GetActorLocation().Y);
for (int32 a = 0; a < 100; a++)
{
FVector Location = FVector(0, 0, 0);
Location = FVector((a / 10 * 100) + vActorLocation.X, a % 10 * 100 + vActorLocation.Y,
GetNoise(a / 100, a % 10));
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride =
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
GetWorld()->SpawnActor<ABlock>(BlockClass, Location, FRotator(0, 0, 0), SpawnParams);
}
}
}
float ARandomWorldGenerator::GetNoise(int x, int y)
{
RandomStream.Initialize(x*13.2 + y*2 + iSeed);
return RandomStream.FRandRange(1, 5);
}
And in the beginplay function I call the function GenerateTerrain.
That is the result (it dosen’t look realy random):
This is the old question:
I am trying to make a function that returns a random int and gets a seed and ervery time I call the funktion with the same seed it has to return the same value.
The code I Made:
int the .h:
FRandomStream RandomStream;
float GetNoise(int x, int y);
UPROPERTY(EditDefaultsOnly)
int32 iSeed = 11110;
and in the .cpp:
float ARandomWorldGenerator::GetNoise(int x, int y)
{
RandomStream.Initialize(iSeed);
return RandomStream.fRandRange(1, 5));
}
But the result isn’t realy random.
May you could help me?