How to make a programmatically generated mesh collidable?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IcyDiamond
:warning: Old Version Published before Godot 3 was released.


So in my project, I’m creating a mesh using SurfaceTool and then assigning it to a MeshInstance. But what I’d like to know is what I need to do in order to be able to make my player collide with it.

My player is a KinematicBody with a simple capsule mesh and CollisionShape.

Do I need to generate a CollisionShape for my mesh to be collidable as well? The documentation says that CollisionShape is an “Editor-only helper”, does that mean that I’m not supposed to create it programmatically?

Please excuse me if this is a stupid question, I’m just getting started with Godot and I ran into a wall here and couldn’t find anything online.

I’m using Godot 3.0-rc3

:bust_in_silhouette: Reply From: davidoc

I used this code to add a box, the floor level was 2 units down:

	var box_sape =
	var extents = Vector3(2.0,2.0,2.0)
	var static_body =
	var coll_shape =

I hope it has not changed for version 3.0

:bust_in_silhouette: Reply From: IcyDiamond

Figured it out!

I added a StaticBody and a CollisionShape to the MeshInstance and I generate a Convex Polygon Shape for the collisions

var col_shape =

Another note: This only seems to work with PRIMITIVE_TRIANGLES

Thanks to Tapio Pyrhönen on Facebook for helping me out!