The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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?

in Engine by (34 points)

2 Answers

+1 vote
Best answer

CollisionShape has a set_shape() which takes in vertices.

by (34 points)
+11 votes

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.

by (864 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. ;)

and how can you do this from GDSCRIPT I can't find a parameter to instantiate a convect collision sibling from GDScript?

extends Spatial

var NodosHijos =  null#variable que va a guardar una lista de objetos

func _ready():
  NodosHijos = get_children()#toma todos los hijos

  for i in NodosHijos:
      #print(i.name)
       var mesh = i.get_child(0)#crea las colsiones y las mallas
      print(mesh.name)
      mesh.create_trimesh_collision() #no work

I use c# so I'm not sure what the exact gdscript function name is, but there should be a mesh method called something like "createconvexcollision".

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.