I have not found any good tutorials for doing so, I tried to convert and use a Unity-based tutorial but that didn't work out
I would atleast like to know how to place a mesh based on the FastNoiseLite function
How do I implement procedurally generated terrain? (Godot 4)
skatefrog I have not found any good tutorials for doing so
Generating a terrain in 3D is a rather non-trivial task. You can try to use special programs for this purpose.
xyz Ok, I'm trying to go by the documentation right now. So this code is supposed to create a triangle, correct?
var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))
# Initialize the ArrayMesh.
var arr_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = vertices
# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance3D.new()
m.mesh = arr_mesh
Well I don't see any triangle in game
skatefrog Well you need to assign a mesh resource to that instance, so the instance knows what mesh data to instantiate. If the script you posted is attached to a MeshInstance3D
node then instead of this:
# Create the Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance3D.new()
m.mesh = arr_mesh
You'll need to do this:
# Assign mesh to the mesh instance
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
mesh = arr_mesh
xyz I'm expecting to see a triangle, as that's what the documentation says will be created with the code.
I don't think the issue is my camera, it's not visible in the editor either, and my camera seems fine for everything else.
It could be that the mesh is too small but I adjusted the vertices values to be higher and that didn't do anything
- Edited
skatefrog You can't see it in the editor because scripts by default don't run in the editor. Note that the triangle will be visible only from one side due to backface culling. So try playing with the camera position. It may also be obscured by something else in the scene. You provided too little information to properly diagnose the problem. Post the minimal reproduction project if you can.
- Edited
"You can't see it in the editor because scripts by default don't run in the editor"
I forgot about that, understood
I had no idea about backface culling till now, I just tried experimenting with various positions of the camera. Camera above the MeshInstance3D, below it, to the left, to the right. By posting the minimal reproduction do you mean code or a video demonstration?
- Edited
- Best Answerset by skatefrog
xyz I just made a project with the minimal things, in the minimal project, the triangle displays. It now also displays in the original project.
The reason why it's suddenly working is because I changed
vertices.push_back(Vector3(0, 500, 0))
vertices.push_back(Vector3(500, 0, 0))
vertices.push_back(Vector3(0, 0, 500))
back to
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))
Which is weird since I only changed it to 500 when it wouldn't display. Problem solved despite the code change only happening after it wouldn't work initially.