diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 08:04:13 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-18 08:04:13 -0400 |
commit | 3dfcc3706f5dcb4b8150e027a02d0eb84c929b26 (patch) | |
tree | 13cf5b93cf6c0f59bbf2b7e6b13931899effa10c | |
parent | 3ac2fb62b67b6446ab31b2455a4cb74069f1c54f (diff) | |
download | godot_wildjam_49-3dfcc3706f5dcb4b8150e027a02d0eb84c929b26.tar.gz godot_wildjam_49-3dfcc3706f5dcb4b8150e027a02d0eb84c929b26.zip |
Generate Rocks in the World Chunks
-rw-r--r-- | ChunkGen.gd | 14 | ||||
-rw-r--r-- | Rock.tscn | 15 |
2 files changed, 23 insertions, 6 deletions
diff --git a/ChunkGen.gd b/ChunkGen.gd index 6e1f0eb..ef29365 100644 --- a/ChunkGen.gd +++ b/ChunkGen.gd @@ -21,6 +21,7 @@ func gen_chunk(chunk): var gen_tree = Spatial.new() gen_tree.name = "gen_tree" chunk.add_child(gen_tree) + iterate_chunk(chunk, Vector2(10.0,10.0), funcref(self,"gen_rocks")) func v2_coords(coords:Vector3): return Vector2(coords.x,coords.z) @@ -33,3 +34,16 @@ func iterate_chunk(chunk,step:Vector2,cb:FuncRef): for x in range(-chunk_size_rounded.x,chunk_size_rounded.x,step.x): for y in range(-chunk_size_rounded.y,chunk_size_rounded.y,step.y): cb.call_func(chunk,Vector2(x,y)) + +onready var Rock = preload("res://Rock.tscn") +const rock_size = 5.0 +func make_rock(chunk,xform:Transform): + var rock = Rock.instance() + rock.transform = xform + chunk.get_node("gen_tree").add_child(rock) + +func gen_rocks(chunk,chunk_coords:Vector2): + 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))) @@ -1,11 +1,10 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://ChunkedMeshInstance.gd" type="Script" id=2] [sub_resource type="ConvexPolygonShape" id=2] points = PoolVector3Array( 2.5, -5, 2.5, 2.5, -5, -2.5, -2.5, -5, -2.5, -2.5, -5, 2.5, 0, 5, 2.5, 0, 5, -2.5 ) -[sub_resource type="PrismMesh" id=1] -size = Vector3( 5, 10, 5 ) - [sub_resource type="OpenSimplexNoise" id=3] octaves = 4 period = 32.0 @@ -26,6 +25,9 @@ normal_enabled = true normal_scale = 1.0 normal_texture = SubResource( 5 ) +[sub_resource type="PrismMesh" id=1] +size = Vector3( 5, 10, 5 ) + [node name="Rock" type="StaticBody"] collision_layer = 8 collision_mask = 0 @@ -34,5 +36,6 @@ collision_mask = 0 shape = SubResource( 2 ) [node name="MeshInstance" type="MeshInstance" parent="."] -mesh = SubResource( 1 ) -material/0 = SubResource( 6 ) +material_override = SubResource( 6 ) +script = ExtResource( 2 ) +_mesh = SubResource( 1 ) |