summaryrefslogtreecommitdiffstats
path: root/world
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-19 04:13:11 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-19 04:13:11 -0400
commit354287265bda1448935c05e76455cff18d57f5da (patch)
treeb4850d49820d3e1b332189e19be36ad69c27d7ea /world
parent32bf9d2024362d45dc351c8f1d0b3b301caf1131 (diff)
downloadgame_jam49-354287265bda1448935c05e76455cff18d57f5da.tar.gz
game_jam49-354287265bda1448935c05e76455cff18d57f5da.zip
Scale rocks based on noise and add a random rotation
Diffstat (limited to 'world')
-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))