0 votes

I have the individual vertices to create a mesh and can create one using the surface tool, however, what I need is to be able to set that mesh as the collision shape. I tried using the CollisionShape node however is says in the docs that it is only used as an editor helper so I should not use it for this purpose. Without it, how can I accomplish this?

asked May 14 in Engine by orosmatthew (29 points)

2 Answers

0 votes
Best answer

CollisionShape has a set_shape() which takes in vertices.

answered May 14 by orosmatthew (29 points)
+1 vote

Follow this steps:

  1. Create an new node of type KinematicBody, RigidBody or StaticBody, depending on what you will use the object for.
  2. Add your mesh as a child of this node. To test it you can add MeshInstance node and create a CubeMesh.
  3. Having the mesh node selected you will see a button appear on top of the 3d viewport saying 'Mesh'.
  4. Click it.
  5. Select create Convex Collision Sibling.

Now you objects should collide.

If not please ask again. Good luck.

answered May 14 by Jowan-Spooner (748 points)

What I want is to do this in gdscript though. I am procedurally generating the mesh using gdscript but need to also then procedurally generate the collision mesh as well. I am just confused as to how to assign the mesh I generate as the shape for the Static Body.

Oh I understand. Have you tried to use the makeconvexfrom_brothers() function of a collision shape node? Don't know if that works.

Oh! I found a setter for the CollisionShape set_shape(). It is exactly what I need because I just need to pass in the vertices. Thanks for your help anyway. ;)

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 How to use this Q&A? before posting your first questions.