Physicalized objects
MeshInstance
-> StaticBody
-> CollisionShape
Select Mesh, select Mesh button in upper left corner ([\]
) -> Create Trimesh static body
Import mesh and create collision:
var terrains = [
preload("res://terrain/terrain1.obj"),
preload("res://terrain/terrain2.obj"),
preload("res://terrain/terrain3.obj"),
preload("res://terrain/terrain4.obj"),
]
func gen_terrain():
# choose a random terrain mesh
choice = round(rand_range(0, terrains.size()-1))
var terrain_mesh = terrains[choice].instance()
for child in terrain_mesh.get_children():
if typeof(child) == 17: #MeshInstance
child.create_trimesh_collision()
# add terrain to parent
add_child(terrain_mesh)
func _ready():
gen_terrain()
apply a custom material:
var MAT = preload("res://mat/vertex_color.tres")
# assuming child is MeshInstance:
child.set_material_override(MAT)