xyz I think you misunderstood the effect I'm trying to achieve. I don't actually want a cylinder in the game world, I want a flat map, splint into chunks and wrapped around the cameras x position.
I need to calculate the coordinates of a point on a circle after a certain arc length, and use that as the x and y values passed into get_noise_3d(), for the z value, I can just use the z value of the vertex, as I don't want wrapping in the z axis.
Here's the code I have thus far:
class_name GameMap
extends Node
var chunk_width: int = 72
var chunk_depth: int = 180
var mesh_resolution: int = 1
var num_chunks: int = 5
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)
var chunk_step = rad_to_deg(chunk_width / radius)
var angle_step = (360.0 / circumference) * (PI / 180.0)
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), 0, vertex.z) * 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_ON
add_child(meshes[segment])
meshes[segment].translate(Vector3(chunk_width * segment + (chunk_width / 2), 0, 0))
func _process(delta):
var map_width = chunk_width * num_chunks
for m in meshes:
var widths_from_camera = (m.global_position.x - camera_rig.global_position.x) / map_width
if (abs(widths_from_camera) <= 0.5):
continue
if (widths_from_camera > 0):
widths_from_camera += 0.5
else:
widths_from_camera -= 0.5
var widths_to_fix: int = widths_from_camera
m.global_position.x -= widths_to_fix * map_width