Spacetime-Meta / spacetime-sdk

The spacetime-sdk is a turnkey virtual environment package for building in the Spacetime Metaverse
https://www.spacetimemeta.io/metaverse/spawn-planet
MIT License
11 stars 2 forks source link

Implement seedable random number generator #140

Closed Liquid-Blocks closed 2 years ago

Liquid-Blocks commented 2 years ago

When creating a terrain of feature using randomness, we need a way to ensure online players see the same terrain.

For example, in the floor is lava demo, the islands are generated randomly during loading time, using Math.random().

for(let i=0; i<35; i++) {
  let position = new THREE.Vector3(Math.random() * 800 - 400, 0, Math.random() * 1000);
  virtualEnvironment.newSolidGeometriesFromSource('../../../resources/objects/rock_platform.glb', position.x, position.y, position.z, Math.random() * 20 + 4);
}

The problem with this generation technique: every user gets a different world since the randomness is not seeded.

To solve this, we need a seedable random number generator so we can insure that every users get the same result when entering a world with randomness features.