Can i create a collisonshape3d manually? like with a mesh?

Godot Version

4.2.1

Question

okay so i am aware that collision meshes need to have constraints that normal meshes don’t have, especially for things like rigidbody. additionally, there are more constraints that are like performance reasons soft limits. however, the built in godot collision generators (trimesh bodies etc) are pretty bad.

i would like to be able to create collision shapes as manually as possible. ideally, i’d like to be able to set a mesh that i’ve imported as my collision mesh. i know that this means that i need to make meshes in specific ways so that they can be colliders, which i am willing to do. i can’t find any way to set a collisonshape to a mesh, besides auto-generating one. those auto-generated meshes are very bad though, and i can’t find a way to make them more accurate. what can i do to have more control over a collisionshape’s mesh?

1 Like

You can use ConvexPolygonShape3D or ConcavePolygonShape3D to create arbitrary collision shapes from 3D points / face data.

2 Likes

It took me a bit to figure that out myself, so I’ll show you how I do it:

First make the mesh local to a scene:
image

Next go to the mesh itself (what I have selected there)

go to the mesh menu at the top:
image

Choose the option that suits your needs best:
image

Select the collision shape produced:
image

Then you can save that for use in general, or add it to a collision area or whatever.

1 Like

all of these options generate a completely different mesh from the input mesh. my question is, can i just set the collision shape to the input mesh?

Yes, that’s what you do with CollisionShape3D it creates.

image

1 Like

this looks like what i want. is there a way for me to import a mesh here? it seems like this menu is for like, manually adding collision shapes

That’s for a single polygon, not a mesh, but in any case you’ll have to specify the points manually if you go that route.

The standard options mentioned by @longplay_games are definitely recommended if you simply want to define a collision object in-editor from source geometry. If you have a second mesh you want to import as collision geometry, you can generate the trimesh collision + StaticBody from the secondary mesh and use it as the CollisionShape for the primary mesh. The trimesh is identical to the provided geometry.

the trimesh is not identical to the provided geometry. in fact it’s a pretty bad approximation in my experience, which is why i’m looking for ways to generate more specific collision.

the trimesh static body generated for this collision mesh i made has the right polygons, but the vertices are all off. maybe this is because of floating point precision? but i can’t find a way to increase the accuracy here and it makes surfaces that should be flat sloped, creates geometry where there is none, an unpredictable collision experience from the player’s perspective.

the high-poly mesh that i’m using for the visual is even more innacurate when you generate a trimesh body, especially down at eye level

not only is this collider sticking out all over, but the angles that it’s creating are very sharp like stairs. this makes walking around feel terrible, because you get caught up on random invisible ledges.

i’d be willing to work with this collision generator if there was a way to make it more accurate. it seems like it is at least approximating the correct geometry but the approximation in my experience has been really bad.

The code for creating the trimesh simply copies the mesh data with no manipulation, so that’s a very interesting discrepancy. The ones I’ve personally generated have been exact matches.

Can you share a copy of your low-poly example above?

Your FBX has a scaling factor of 2500 (as reported by Godot; 25.00 when imported into Blender). There’s also a -0.000016 degree rotation on the x axis which probably doesn’t help.

Baking the scale + rotation in Blender and re-exporting the FBX allows the trimesh to generate accurately in Godot.

2 Likes

oh that could be it. it does look a bit like a floating point precision problem and that would make sense

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.