This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm aiming create a house procedural generator, for now I can create 4 walls in a rectangle shape, here is the code:

var myMesh = MeshInstance.new()
myMesh.mesh = CubeMesh.new()
myMesh.mesh.size = Vector3(x, y, wall_thickness)
myMesh.create_trimesh_collision()
add_child(myMesh)

var myMesh2 = MeshInstance.new()
myMesh2.mesh = CubeMesh.new()
myMesh2.mesh.size = Vector3(x, y, wall_thickness)
myMesh2.translate(Vector3(0, 0, z))
myMesh2.create_trimesh_collision()

add_child(myMesh2)

var myMesh3 = MeshInstance.new()
myMesh3.mesh = CubeMesh.new()
myMesh3.mesh.size = Vector3(wall_thickness, y, z)
myMesh3.translate(Vector3(x/2, 0, z/2))
myMesh3.create_trimesh_collision()

add_child(myMesh3)

var myMesh4 = myMesh3.duplicate()
myMesh4.translate(Vector3(-x, 0, 0))
myMesh4.create_trimesh_collision()

add_child(myMesh4)

Now I want to add doors but I can't find out a manner to do that, the best way I tought of was to subract the door passage and then add the door mesh, but don't find any exemple for mesh subtraction in code

Godot version 3.3.2
in Engine by (76 points)

1 Answer

0 votes

You can use a GSGcombiner with it's children as CSGboxes (and other GSGshapes).

by (248 points)

Thanks, here is an example in code, I added in the CSGcombiner node script

    var wall = CSGBox.new()
wall.width = x
wall.height = y
wall.depth = 0.2
wall.translate(Vector3(0, y/2, 0))  

add_child(wall)

var door_passage = CSGBox.new()
door_passage.width = 2
door_passage.height = 4
door_passage.depth = 1
door_passage.operation = OPERATION_SUBTRACTION 
door_passage.translate(Vector3(0, door_passage.height/2, 0))    
add_child(door_passage)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.