system
March 19, 2020, 9:40am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
huahuapro
func _generate_mesh():
_generate_vertices()
_generate_UVs()
_generate_indices()
_generate_normals()
var mesh = ArrayMesh.new()
var data = []
data.resize(ArrayMesh.ARRAY_MAX)
data[ArrayMesh.ARRAY_VERTEX] = vertices
data[ArrayMesh.ARRAY_TEX_UV] = UVs
data[ArrayMesh.ARRAY_INDEX] = indices
data[ArrayMesh.ARRAY_NORMAL] = normals
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLE_STRIP, data)
mesh.create_trimesh_shape()
return mesh
thanks!
system
March 19, 2020, 6:36pm
2
Reply From:
Zylann
mesh.create_trimesh_shape()
This line returns a shape for use in collisions, but you aren’t using the return value. So it runs for nothing.
You should grab the result of create_trimesh_shape
and assign it to a CollisionShape
node in your scene.
thanks for the fast answer.
i’m new to coding and godot :(, can you tell me how to assign it to a Collisionshape node?
and here’s my func that use:
func _initialize():
if is_initialized:
return
if block_map == null:
return
mesh_node = get_node_or_null(block_map)
if mesh_node == null:
return
_generate_noise()
mesh_node.mesh = _generate_mesh()
is_initialized = true
i try to code: mesh_mode.create_trimesh_shape(), but it gives an error.
thanks!
huahuapro | 2020-03-19 23:50
Do you know how to setup collision shapes in the first place? I suggest you take a look at how they work: Physics introduction — Godot Engine (stable) documentation in English
The shape you obtain from the generated mesh is a resource.
Your node should have (or be) a StaticBody
node, with a CollisionShape
node as child. CollisionShape
has a property named shape
, and that’s the one you need to assign the return value of create_trimesh_shape()
.
Zylann | 2020-03-20 00:37
are you the man who create the voxel plugin?
omg, i think you are!
huahuapro | 2020-03-20 06:36