summaryrefslogtreecommitdiffstats
path: root/world/chunk/ChunkGen.gd
diff options
context:
space:
mode:
Diffstat (limited to 'world/chunk/ChunkGen.gd')
-rw-r--r--world/chunk/ChunkGen.gd34
1 files changed, 26 insertions, 8 deletions
diff --git a/world/chunk/ChunkGen.gd b/world/chunk/ChunkGen.gd
index 5e99be8..d60b2e5 100644
--- a/world/chunk/ChunkGen.gd
+++ b/world/chunk/ChunkGen.gd
@@ -8,14 +8,20 @@ func _set_chunk_size(val):
chunk_size = val * 2.0
onready var noise = OpenSimplexNoise.new()
+onready var rng = RandomNumberGenerator.new()
+var _seed
func _ready():
randomize()
- noise.seed = randi()
- noise.octaves = 4
- noise.period = 64
- noise.persistence = 0.001
- noise.lacunarity = 2.0
+ self._seed = randi()
+ self.noise.seed = self._seed
+ self.noise.seed = 0
+ self.noise.period = 16
+ self.noise.persistence = 0
+ self.rng.seed = self._seed
+
+func rng_2dv(coords:Vector2):
+ self.rng.seed = hash(coords)
func gen_chunk(chunk):
var gen_tree = Spatial.new()
@@ -43,7 +49,19 @@ func make_rock(chunk,xform:Transform):
chunk.get_node("gen_tree").add_child(rock)
func gen_rocks(chunk,chunk_coords:Vector2):
+ var coords = v3_coords(chunk_coords)
+ var basis = Basis()
var world_coords = chunk_coords + v2_coords(chunk.transform.origin)
- var noise_val = self.noise.get_noise_2dv(world_coords)
- if noise_val > 0.4:
- make_rock(chunk,Transform(Basis().scaled(Vector3(2.0,2.0,2.0)),v3_coords(chunk_coords)))
+ self.rng_2dv(world_coords)
+ var rng_val = self.rng.randf_range(0.0,TAU)
+ basis = Basis(Vector3.UP,rng_val) * basis
+ var noise_val = self.noise.get_noise_2dv(world_coords * 0.125)
+ if noise_val < 0.4:
+ return
+ noise_val = min(noise_val,0.6)
+ noise_val -= 0.4
+ noise_val /= 0.2
+ noise_val = lerp(1.0,4.0,noise_val)
+ basis = basis.scaled(Vector3.ONE*noise_val)
+ coords.y += (noise_val*5.0)-5.0
+ make_rock(chunk,Transform(basis,coords))