This is example project, showing how to use Perlin Noise for procedural generation of terrain from 2d tiles. For different noises explore Noise repo.
Use WASD
to move camera, ZX
to zoom, ui button to reset map.
All map-building logic located in main.rs
for easier exploration.
(While running this project, you can move camera with WASD)
I didn't find any for bevy, so I implemented this solution found on Unity forums.
For showcase, I used simple color tiles, feel free to use any tilesets you want, and custom tiling function.
Version | Bevy Version |
---|---|
0.1 (current) | 0.12 |
- | - |
For terrain tiles I used terrace inverted noise with threshold for ground\water tiles.
pub fn terrain_noisemap(seed: u32) -> NoiseMap {
let perlin = Perlin::new(seed);
let terrace_inverted = Terrace::new(perlin)
.add_control_point(-1.0)
.add_control_point(-0.5)
.add_control_point(0.1)
.add_control_point(1.0)
.invert_terraces(true);
PlaneMapBuilder::new(terrace_inverted)
.set_size(NOISEMAP_SIZE.0, NOISEMAP_SIZE.1)
.build()
}
For flora I used hybridmulti perlin noice
pub fn flora_noisemap(seed: u32) -> NoiseMap {
let hybrid_multi = HybridMulti::<Perlin>::new(seed);
PlaneMapBuilder::new(hybrid_multi)
.set_size(NOISEMAP_SIZE.0, NOISEMAP_SIZE.1)
.build()
}
Also, I implemented transition detection in resulting noise to place transition tiles correctly, but this problem lies outside of topic a bit.