+1 vote

Hello, I figured ou how to make an octahedral shape with collision shape :

func _ready():
var array_of_positions = [........]
self.shape = ConvexPolygonShape.new()
self.shape.set_points(array_of_positions)

but cannot make it with mesh, even manually it is not possible, is there a reason for this ?
thx
(i tried to draw lines with immediate geometry but look like way too complicated)

in Engine by (114 points)
edited by

1 Answer

0 votes

If you have a mesh already, you can create the collision shape like this:

Click on a mesh instance in editor, and there will show up a button Mesh (in top line near Transform and View), where you can create Trimesh Static body and Convex static body.

In code, it looks like this:

var oMeshInstance = get_node("/root/scene" + sMesh)
oMeshInstance.create_trimesh_collision()
by (25 points)

thank you whypay for your answer, I see now what I was missing.
I don't have a mesh, so is there a way to "make godot create based on just an array of points ?

I am just working on collisions now with simples convex and I just want to visualise them to check behaviour.

from an array of points, to get a mesh I would need to add an additional array of faces (3points), right ?
considering I have just convex polygon , does any available tool in godot can do it for me ? I don t care about material stuff

What kind of mesh shape do you need?
If its a simple shape, you can first create a MeshInstance, then you add a Mesh (just click on Mesh in MeshInstance). You can choose from predefined shapes (e.g. QuadMesh, or CubeMesh). These can be modified with parameters (height, width etc.).
If you need some points, you can add a ArrayMesh, I suppose, and create your own faces (add_surface_from_arrays).
You can also import meshes from other 3d apps, like blender or 3ds max.

You can also make your collision shapes visible in Debug menu.

it is octahedron shapes I want to render, which is not available in the suggested primitive mesh in the editor.

ArrayMesh only offer me to make Custom Aabb shape.
since it look really strait forward to make a convex polygon with CollisionShape node I expected the same from mesh.

Make collision shape visible is processed (I think) at the beginning and happens before I configure my polygon (by code). so it doesn't work for me.

Since I only deal with basic polygons I wish I could not have to deal with other "mesh" software like blender.

if I use add_surface_from_arrays I have to define manually which vertices define each face , right ? I cannot just throw all my points and let godot define the faces.

If you debug with "Visible collisoion shapes", the collision shapes are visible once you create them - in the editor or by code. I use create_trimesh_collision() in code on level load, and the collsion shapes are visible for me.

You can create a sphere mesh, set Radial Segments to 4, and Rings to 1, then you have an octahedron.

Select your object, then click on the "Mesh" button in top menu and select "Create Trimesh Static Body", this will add collsion shapes and rigid body.

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.
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 webmaster@godotengine.org with your username.