Procedural Map Generation

Godot Version

4.2.1

Question

I’m trying to generate a map in chunks such that I can wrap those chunks around the cameras x position. I’ve got it currently where it will wrap the chunks around the camera, and generate 3D noise in effectively a 2D manner. For each chunk, it will sample noise at the correct position in the x-axis (vertex.x + (chunk_width * segment), where segment corresponds to the ordinal ID of the segment, either 0, 1, 2, or 3). Now however what I need to do is sample the noise in a cylinder.

I need to calculate the x and y coordinate after a certain angle, determined by dividing 360 by the number of vertices there are in the X-Axis. I know the answer will look something like the following: get_noise_3d(x, radius * sin(current_angle), radius * cos(current_angle)).
Here’s a gif of it in its current state:

Here’s the code I’m working with:

class_name GameMap
extends Node

var chunk_width: int = 90
var chunk_depth: int = 180
var mesh_resolution: int = 1
var num_chunks: int = 4

var meshes: Array[MeshInstance3D]

@export var noise: FastNoiseLite = FastNoiseLite.new()
@export var camera_rig: Node3D = Node3D.new()

func _ready():
	var circumference = chunk_width * num_chunks * mesh_resolution
	var radius = circumference / (2 * PI)
	for segment in range(0, num_chunks):
		var plane_mesh = PlaneMesh.new()
		plane_mesh.size = Vector2(chunk_width, chunk_depth)
		plane_mesh.subdivide_width = chunk_width * mesh_resolution
		plane_mesh.subdivide_depth = chunk_depth * mesh_resolution
		plane_mesh.material = preload("res://mat_grass.tres")

		var surface = SurfaceTool.new()
		var data = MeshDataTool.new()
		surface.create_from(plane_mesh, 0)

		var array_mesh = surface.commit()
		data.create_from_surface(array_mesh, 0)

		for i in range(data.get_vertex_count()):
			var vertex = data.get_vertex(i)
			vertex.y = noise.get_noise_3d(vertex.x + (chunk_width * segment), vertex.z, 0) * 5
			data.set_vertex(i, vertex)

		array_mesh.clear_surfaces()

		data.commit_to_surface(array_mesh)
		surface.begin(Mesh.PRIMITIVE_TRIANGLES)
		surface.create_from(array_mesh, 0)
		surface.generate_normals()

		meshes.append(MeshInstance3D.new())
		meshes[segment].mesh = surface.commit()
		meshes[segment].create_trimesh_collision()
		meshes[segment].cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
		add_child(meshes[segment])
		meshes[segment].translate(Vector3(chunk_width * segment + (chunk_width / 2), 0, 0))

vertex.y = noise.get_noise_3d(radius * cos(deg_to_rad(((segment * chunk_width) + vertex.x) * angle_step)), radius * sin(deg_to_rad(((segment * chunk_width) + vertex.x) * angle_step)), vertex.z) * 5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.