For the ground in a 3D world I create a StaticBody3D.

Now GPT tells me to add CollisionShape3D and MeshInstance3D. But I would have to copy and paste my Transform values between both nodes whenever I move the ground. Violates don't repeat yourself horribly.

How can I point both nodes to the same Transform coordinates. Or make the mesh a collision object itself so I don't need CollisionShape3D?

I feel this is part of some bigger design principle on sharing data between Nodes that I didn't see in the tutorials. I can't imagine anyone pasting coordinates around between all siblings of an object on every change.

  • xyz replied to this.

    signup Parent both to a collision object. Typically the StaticBody3D is used for terrains.

    Thanks. I don't understand what you said

    • xyz replied to this.

      signup When you move the ground, you move the static body. The mesh instance and the collision shape need to be its children so they'll automatically follow along. You don't need to move them individually.

      To make a collision shape out of a mesh instance you can select the mesh instance node, click on the Mesh button on the toolbar and select Create Trimesh Collision Sibling. It will create a collision shape node with a proper concave collider derived from mesh instance's mesh data.

      No, not moving. Scale. And I don't want to have create a new collision every time I change the mesh. I want them to share Transform values.

      • xyz replied to this.

        signup It doesn't matter; move, translate, scale. If you don't change the vertex data, then you don't need to create a new mesh every time you transform it. The mesh is created only once and all subsequent transformations are supposed to be done via StaticBody3D node. That way your visual mesh and your collision mesh always coincide.

        Just checking, so you're saying if I set the Scale of the StaticBody3D Ground here, then both nodes below it will have the same Scale?

        • xyz replied to this.

          signup All children will inherit all of the transformations of the parent node, including scale, yes. That's the whole point of organizing nodes in a tree structure in Godot.

          Btw you typically want the collision shape node and the mesh instance node to be siblings, not having one as a child of the other like your scene tree currently shows. Same for the character body node.

          8 months later

          Thanks @xyz , I got this to work. But two final questions:

          • Is there any way to automatically make the mesh the collisionshape? Because whenever I adjust my mesh, or import a new one from Blender, I have to recreate the collisionshape with your instructions above. Otherwise I guess I have to create a plugin that iterates through every mesh in every scene in my project, deletes the collisionshapenode and creates a new one. I can't even imagine how tedious that will get when I have animated meshes.
          • As you can see in my screenshot, my tree is made in Godot, not Blender, so it has two meshes. But the collision shape generator ignores the the child mesh. Is there a way to combine meshes, or get the generator to take the full mesh with children into account please?

          • xyz replied to this.

            @signup

            whenever I adjust my mesh, or import a new one from Blender, I have to recreate the collisionshape

            You do not need to add a CollisionShape3D right away. You can finish adjusting your Mesh first then create the CollisionShape3D at the end.

            so it has two meshes. But the collision shape generator ignores the the child mesh

            First, move your meshes to this:

            Tree
            -MeshInstance3D (green part)
            -MeshInstance3D2 (brown part)

            You then can SHIFT select both meshes and do the create collision sibling.
            However, I found that it will create both collisionshapes at the last selected mesh's origin. You have to move one of them to match your other mesh. (I'm using Godot 4.3)